Tkinter CheckButton variables

E

Elaine Jackson

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()
 
K

klappnase

Elaine Jackson said:
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()

c[variable'] returns (of course) cVb1 and therefore will always be true.
You should use

if cVb1.get():
(etc.)

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top