When you're creating it, it takes a variable
keyword argument. Pass it an IntVar
from Tkinter
. Checking or unchecking the box will set that value contained by var
to the corresponding boolean state. This can be accessed as var.get()
:
checked => var.get()
not checked => not var.get()
>>> root = Tkinter.Tk()
>>> var = Tkinter.IntVar()
>>> chk = Tkinter.Checkbutton(root, text='foo', variable=var)
>>> chk.pack(side=Tkinter.LEFT)
>>> var.get() #unchecked
0
>>> var.get() #checked
1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…