from tkinter import * class RBDemo: def __init__(self, win): self.ivPressed = IntVar() #Put the first group of radio buttons in their own frame. f1 = Frame(win, borderwidth=30, relief=RAISED) rb1 = Radiobutton(f1, command=self.clicked, text="One", variable=self.ivPressed, value=1) rb2 = Radiobutton(f1, text="Two", variable=self.ivPressed, value=2) rb3 = Radiobutton(f1, text="Three", variable=self.ivPressed, 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.ivPressed.set(1) #Make a second group of radiobuttons in their own frame. #No button is set by default, and their values are strings. self.svPressed = StringVar() f2 = Frame(win, borderwidth=20, relief=SOLID) rb4 = Radiobutton(f2, text="Green", variable=self.svPressed, value="greeeeen") rb5 = Radiobutton(f2, text="Red", variable=self.svPressed, value="reeeeed") 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("Numeric radio buttons have this pressed:", self.ivPressed.get()) print("Color radio buttons have this pressed:", self.svPressed.get()) print() mw = Tk() app = RBDemo(mw) mw.mainloop() # questions - Can has callback?