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

1. 2. The following program creates a simple Tkinter canvas on a window similar

ID: 3906258 • Letter: 1

Question

1.

2.

The following program creates a simple Tkinter canvas on a window similar to what's shown at right, initialized by the color #000000 (Black) import random import tkinter class App: def init (self): self._root tkinter.Tk() self.-canvas = tkinter·Canvas(master = self.-root, height = see, background = 18) width = 5ee, .#eeeee.) self.-canvas . grid( row , column -e, padx 10, pady self. current#000000 self._previous[self._current] self._canvas.bind self._on_left click) self._canvas.bind , self._on_right_click) &Explain; &Explain; def start(self) self._root.mainloop() def on left click(self, event): self._previous.append (self._current) randomCol '4. for x in range(6): randomCol += str( random. randint(8, 9)) self._current randomCol self._canvas.delete(tkinter.ALL) self. _canvas. configure (background randomCol) def _onright_click (self, event): if len self._previous) selfcurrent - ,#eeeeee. - else: self-current = self .-previous [-1] self._previous. pop() self._canvas.configure (background-self._current) Explain what events the application responds toand what happens when those events are triggered be specific as possible

Explanation / Answer

CHEGG POLICY: ONLY ONE QUESTION PER POST IS ALLOWED , PLEASE ABIDE BY THE CHEGG POLICY POST FURTHER QUESTIONS ACCORDINGLY

SOLUTION

Question 1:

self._canvas.bind('<Button-1>', self._on_left_click)

This line of code binds the event of clicking of left mouse button to the method _on_left_click , Whenever left mouse button is clicked it will trigger the calling of the function _on_left_click

self._canvas.bind('<Button-2>', self._on_right_click)

This line of code binds the event of clicking of middle mouse button ( Button-2 ) to the method _on_right_click , whenever middle mouse button is clicked it will trigger the calling of the functiion _on_right_click

Events that the application responds to :-

The application responds to the following events

When the event of left mouse button click is triggered then the application calls the _on_left_click method and this method generates a random color , and chage the canvas background to this newly randomly generated color and append this color to the list _previous which is the list of previous colors

When the event of middle mouse button click is triggered then the application calls the _on_right_click method and this method change the color of the canvas to the last color that is in the _previous color list , and pop (remove) the color from the list , if the list is empty then it sets the canvas background color to '#000000' which is black

Summary : The left click changes canvas color from initial black to a random color and the middle click brings back the previous colors all the way to black in subsequent clicks .

PLEASE RATE ! !

Thanks !