Tkinter CheckButton variables

Elaine Jackson elainejackson7355 at home.com
Thu Jul 1 00:59:26 EDT 2004


My CheckButton variables seem always to be true, whether the box is checked or
not, which makes them considerably less useful. Following is a little script
that illustrates the difficulty. Any help will be greatly appreciated. Thank
you.

###########################################

from Tkinter import *

def bCommand():
    if c['variable']: ## ALSO TRIED: if cVbl
        print 'bool(cVbl)==True'
    else:
        print 'bool(cVbl)==False'

root = Tk()
cVbl = IntVar()
c = Checkbutton(root,variable=cVbl)
c.pack(side=LEFT)
b = Button(root,height=1,width=10,command=bCommand)
b.pack(side=LEFT)
root.mainloop()





More information about the Python-list mailing list