Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 4 The following program creates a simple Tkinter canvas on a window simi

ID: 3904233 • Letter: P

Question

Problem 4 The following program creates a simple Tkinter canvas on a window similar to what's shown at right, initialized by the color H000000 (Black). import random import tkinter class App: def init (self): self. _root tkinter.Tk self._canvas tkinter.Canvas (master- self._root, width 5e0, height see, background 800e90") 18) self. canvas.grid(row- e, column- e, padx -18, pady self._current 890009e self._previous [self._current] self.-canvas .bind('?Button-1s", self._A-left-click) self._canvas.bind(', self..on_right click) BExplain Explain def start(self): self._root.mainloop() def on left click(self, event): self._previous.append(self._current) randomco1 " .#. for x in range(6): randomColstr(random.randint (8, 9)) self._current randomCol self._canvas.delete(tkinter.ALL) self._canvas.configure(background randomcol) def _on_right click(self, event): if len(self._previous)8: self-current .#000000. - else: self._current self._previous[-1] self._previous.pop() self._canvas.configure(background-self._current) Explain what events the application responds to and what happens when those events are triggered- be specific as possible.

Explanation / Answer

Answer : ------------------>>>>>>>>>

Here first bind function of tkinter canvas bind the Button-1 means left mouse button to the function _on_left_click function of App and Button-2 bind will bind the middle click of mouse to the function _on_right_click if you want to bind with right button of mouse than put Button-3 .

_on_left_click : ------------>>>>>>

it will append the current background color to the previous list than it generate a new random color after that it make current color the newly generated color and it will change the background color of canvas

_on_right_click : -------------->>>>>>>>>>

this function first check the previous list is it empty or not if it is empty then it put black color on the current background color and do nothing. If the previous list is not empty then it choose the previous color from previous list and make it current color and pop the previous list and it will also change the background color to the current color

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote