Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1button.bind('<Button-1>', on_click) | ALinks a left mouse click on the button (the event trigger) to the on_click handler, so on_click runs when the click happens | |
| 2def on_click(event): | BThe handler is called with () instead of being passed by name. It runs immediately and not when the click happens. It should be on_click. | |
| 3An object trigger: the interface object the user acts on, such as a button, which is the source of the event | CDefines an event handler, the code that runs when its trigger happens | |
| 4An event trigger such as a key press can be linked to a handler so the program responds | Droot.bind('<Key>', on_key) | |
| 5button.bind('<Button-1>', on_click()) | EThe handler has no event parameter, but bind() passes an event object, so a TypeError occurs when a key is pressed. It should be def on_key(event): | |
| 6def on_key(): print('Key pressed') root.bind('<Key>', on_key) | Fbutton = tk.Button(root, text='Go') |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
event trigger — An action on an interface object, such as a click or key press, that starts a response in the program. The code that responds is called an event handler.def on_click():
print("Button clicked!")btn = Button(root, text="Go", command
=on_click)root.bind("<Key>", on_key)root.bind("<Button-1>", on_click)root.mainloop()