Reputation: 165
How would I change my code to allow multiple buttons to be selected, rather than limiting to one being selected.
from tkinter import *
master = Tk()
master.title("Interests")
v = IntVar()
MODES = [
("Monochrome", "1"),
("Grayscale", "2"),
("True color", "3"),
("Colour separation", "4"),
]
v = StringVar()
v.set("0") # sets all visable buttons to unchecked
for text, mode in MODES:
b = Radiobutton(master, text=text, variable=v, value=mode)
b.pack(anchor=W)
Upvotes: 1
Views: 6465
Reputation: 385800
It has been a convention for decades that radiobuttons are for making a single selection from a set of choices. Checkbuttons are for allowing multiple selections.
You need to switch from radiobuttons to checkbuttons. Each checkbutton needs to be given its own variable.
Here is an article by a well known usability expert which covers the use of each type of button:
https://www.nngroup.com/articles/checkboxes-vs-radio-buttons/
Upvotes: 3