RadioButtons and CheckButton : Checkbutton « Tkinker « Python Tutorial

RadioButtons and CheckButton
from Tkinter import *

class SelectionTest :
    def __init__(self) :
        self.root = Tk()
        self.group_1 = IntVar()

        Radiobutton(self.root, text="Option 1:", variable=self.group_1, value=1).pack(anchor=W)
        Radiobutton(self.root, text="Option 2:", variable=self.group_1, value=2).pack(anchor=W)
        Radiobutton(self.root, text="Option 3:", variable=self.group_1, value=3).pack(anchor=W)

        Label(self.root, text="Group 2:").pack()

        self.group_2 = IntVar()
        Radiobutton(self.root, text="Option 2-1:", variable=self.group_2, value=1).pack(anchor=W)
        Radiobutton(self.root, text="Option 2-2:", variable=self.group_2, value=2).pack(anchor=W)
        Radiobutton(self.root, text="Option 2-3:", variable=self.group_2, value=3).pack(anchor=W)

        self.check_1 = IntVar()
        self.check_2 = IntVar()
        self.check_3 = IntVar()
        Checkbutton(self.root, text="Text", variable=self.check_1).pack(anchor=W)
        Checkbutton(self.root, text="RTF", variable=self.check_2).pack(anchor=W)
        Checkbutton(self.root, text="Word", variable=self.check_3).pack(anchor=W)


st = SelectionTest()
print "Group 1 selection: "+str(st.group_1.get())
print "Group 2 selection: "+str(st.group_2.get())
print "Check Box 1: " + str(st.check_1.get())
print "Check Box 2: " + str(st.check_2.get())
print "Check Box 3: " + str(st.check_3.get())

18.6.1.Check buttons, the easy wayCheck buttons, the easy way
18.6.2.Check buttons, the hard way (without variables)Check buttons, the hard way (without variables)
18.6.3.Checkbox button barCheckbox button bar
18.6.4.Use Check buttons to change the fontUse Check buttons to change the font
18.6.5.React to the check state of a check boxReact to the check state of a check box
18.6.6.RadioButtons and CheckButtonRadioButtons and CheckButton