Getting Checkbutton state

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

Leave a Comment