from tkinter import * class RBDemo: def __init__(self, win): self.v = IntVar() #Put the first group of radio buttons in their own frame. f1 = Frame(win, borderwidth=3, relief=RAISED) rb1 = Radiobutton(f1, text="One", variable=self.v, value=1) rb2 = Radiobutton(f1, text="Two", variable=self.v, value=2) rb3 = Radiobutton(f1, text="Three", variable=self.v, value=3) rb1.pack(anchor=W); rb2.pack(anchor=W); rb3.pack(anchor=W) f1.pack(side=LEFT) #Button one will be selected by default self.v.set(1) #Make a second group of radiobuttons in their own frame. #No button is set by default, and their values are strings. self.v2 = StringVar() f2 = Frame(win, borderwidth=2, relief=SOLID) rb4 = Radiobutton(f2, text="Green", variable=self.v2, value="r") rb5 = Radiobutton(f2, text="Red", variable=self.v2, value="g") rb4.pack(anchor=W); rb5.pack(anchor=W) f2.pack(side=RIGHT) #Make a button that prints what each value is when clicked b = Button(win, text="try it!", command=self.clicked) b.pack(side=BOTTOM, fill=BOTH, expand=1) def clicked(self): print("button clicked!") print("v is:", self.v.get()) print("v2 is:", self.v2.get() ) mw = Tk() app = RBDemo(mw) mw.mainloop()