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 | |
|---|---|---|
| 1tk.Button(root, text='Save', command=save_data) | ACreates a button labelled Save that runs the function save_data each time it is clicked | |
| 2def on_click(): | Bbtn = tk.Button(root, text='Go', command=show) | |
| 3Pass the handler to command by name only, with no brackets, so it runs on click and not straight away | CThe button is created before show is defined, so Python raises a NameError. Define the handler function first, then create the button. | |
| 4A handler can read text from an Entry with .get() and update a Label with .config() | Ddef greet(): lbl.config(text='Hi ' + ent.get()) | |
| 5tk.Button(root, text='Go', command=show()) | EBrackets after show make the function run immediately when the button is created, not when it is clicked. Use command=show. | |
| 6tk.Button(root, text='Go', command=show) def show(): print('Hi') | FDefines an event handler function that will run when the user clicks the button |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
tk.Button(root, text='Go', command=show) — Makes a button that runs the function show when clicked. Write the function name with no brackets, or it runs straight away instead of on click.b = tk.Button(root, text='Go', command=show)b = tk.Button(root, text='Go', command=show)def greet():
label.config(text='Hi!')
b = tk.Button(root, text='Go', command=greet)def greet():
label.config(text=entry.get())
b = tk.Button(root, text='Go', command=greet)def show():
label.config(text='Clicked!')
b = tk.Button(root, text='Go', command=show)