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 | |
|---|---|---|
| 1Radiobutton(root, text="Small", variable=size, value="S") | Asize = StringVar() Radiobutton(root, text="S", variable=size, value="S") Radiobutton(root, text="L", variable=size, value="L") | |
| 2ttk.Combobox(root, textvariable=colour, values=["Red", "Blue"]) | BCreates one radio option that sets the shared variable size to "S" when the user selects it | |
| 3A Checkbutton stores True or False in a BooleanVar, so you read the tick state with .get() | CNo value= is given, so the buttons have no distinct value to store and cannot be told apart. Add value="S" and value="L". | |
| 4A group of Radiobuttons shares ONE variable so that only one option can be selected at a time | Dagree = BooleanVar() Checkbutton(root, text="I agree", variable=agree) print(agree.get()) | |
| 5Radiobutton(root, text="Small", variable=size) Radiobutton(root, text="Large", variable=size) | EThe variable is printed instead of reading its contents. Use choice.get() to get the user's pick. | |
| 6choice = StringVar() print(choice) | FCreates a drop-down list whose chosen item is stored in the variable colour |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
StringVar() — A tkinter variable that stores the user's pick from a choice control (Checkbutton, Radiobutton or Combobox). Link it with variable= and read the choice with .get().ok = tk.BooleanVar()
tk.Checkbutton(win, text="Yes", variable=ok)tk.Radiobutton(win, variable=size, value="S")size = tk.StringVar(value="S")
tk.Radiobutton(win, variable=size, value="M")box = ttk.Combobox(win, values=["S", "M"])size = tk.StringVar(value="S")
print("Chosen:", size.get())