Sinan Yumurtac─▒ Sinan Yumurtac─▒ - 1 month ago 6x
Python Question

Python 3.5 Tkinter How to separate 2 sets of radio buttons

my first question here.

I'm currently writing a GUI with tkinter, Python 3.5

I have a settings frame in my application and I have radiobuttons to let the user change them. There is no problem when I have only one set of radiobuttons but when I add a second set of radiobuttons, python thinks that they all belong to the same set and the user can pick only one of the 6 radiobuttons(I want the user to be able to pick a total of two,1 for each set). Is there a way to tell tkinter/python that there are 2 sets of radiobuttons? I searched stack overflow with a few keywords but most of the questions are about how to get values from radiobuttons and none of them answer my question.

Here is a example code of radiobuttons, to help you imagine the situation;

import tkinter as tk
#I'm not writing things like frames or stuff, this is just to
#tell you how my radiobuttons are categorized

#I want these to be separate;
s1r1=tk.RadiobuttonI(root,text="Red")#Set 1-Radiobutton 1
s1r2=tk.RadiobuttonI(root,text="Green")#Set 1-Radiobutton 2
s1r3=tk.RadiobuttonI(root,text="Blue")#Set 1-Radiobutton 3
#than these;
s2r1=tk.RadiobuttonI(root,text="1")#Set 2-Radiobutton 1
s2r2=tk.RadiobuttonI(root,text="2")#Set 2-Radiobutton 2
s2r3=tk.RadiobuttonI(root,text="3")#Set 2-Radiobutton 3

Thanks a lot!


You didn't bind two different variables to your button groups. Each Radiobutton group has to be associated with a single StringVar() or IntVar().

v1 = tk.StringVar()
v2 = tk.StringVar()
# Group 1
s1r1=tk.RadiobuttonI(root,text="Red", variable=v1)
s1r2=tk.RadiobuttonI(root,text="Green", variable=v1)
s1r3=tk.RadiobuttonI(root,text="Blue", variable=v1)
# Group 2
s2r1=tk.RadiobuttonI(root,text="1", variable=v2)
# etc..