I have set up some Radiobuttons in Tkinter (Python 3). These are
btPurple. I need to make sure that only one of them can be selected at a time. How can I do this? Well, let’s first look at the basic setup for tkinter radiobuttons without them being mutually exclusive:
This doesn’t work because we haven’t set up a variable that the Radiobuttons route to. Let’s look at the TkDocs documentation for tkinter radiobuttons:
variable : A variable linked to the radiobutton; when the variable is changed, the radiobutton will reflect the new value, while if the user selects the radiobutton, the variable’s value will be updated. If the variable has not been initialized, the radiobutton is shown in an indeterminate state, which usually implies that a choice has not yet been made (and that a default choice is inappropriate).
We see that we can add in a variable parameter into our
That could look something like this:
In this case,
self.colorVar will be automatically set to whichever radio button is selected.