tkinter Checkbutton widget returning wrong boolean value

Viewed 8325

I have a simple GUI here that's suppose to return a boolean value depending on whether the check button is checked or not. I've set the boolean variable to False hence the empty check button. What I don't understand is that when I check the button, the function binded to that widget returns a False instead of True. Why is that?

Here's the code...

from tkinter import *
from tkinter import ttk

def getBool(event):
    print(boolvar.get())

root = Tk()

boolvar = BooleanVar()
boolvar.set(False)

cb = Checkbutton(root, text = "Check Me", variable = boolvar)
cb.bind("<Button-1>", getBool)
cb.pack()

root.mainloop()

when checking the empty button the function outputs...

False

Shouldn't it return True now that the button is checked?

1 Answers
Related