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 | |
|---|---|---|
| 1root.bind('<KeyPress>', on_key) | AThe handler has no event parameter, so event is undefined and tkinter cannot pass the key press in. It should be def on_key(event): | |
| 2event.keysym | BTells tkinter to call the function on_key every time any key is pressed in the window | |
| 3A handler function must have a parameter to receive the event that tkinter passes in | Cdef on_key(event): | |
| 4Respond only when a specific key, such as the Up arrow, is pressed | DThe handler is called with brackets, so it runs straight away instead of waiting for a key press. Pass on_key without (). | |
| 5root.bind('<KeyPress>', on_key()) | EGives the name of the key that was pressed, such as 'a', 'Up' or 'space' | |
| 6def on_key(): print(event.keysym) | Fif event.keysym == 'Up': |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
root.bind('<KeyPress>', handler) — Links a key press to a handler function. Each time a key is pressed, tkinter calls handler(event), and event.keysym tells you which key it was.root.bind('<KeyPress>', handler)def handler(event):
print(event.keysym)key = event.keysymif event.keysym == 'Up':
print('Up arrow')def press(event):
print(event.keysym)
root.bind('<KeyPress>', press)