[Tkinter-discuss] Unexpected Checkbutton behaviour

Gerardo Juarez gerardo at computo-industrial.com.mx
Wed Nov 29 04:07:47 CET 2006


Hi, 

I'm having problems with a widget, which  I've been able to isolate to the 
following example:

from Tkinter import *

def display():
    global x
    print x

root = Tk()
x = 0
check = Checkbutton(root, variable=x)
check.pack()
button = Button(text='Display variable', command=display)
button.pack()
root.mainloop()

As far as I understand the reference, when I click the button, the
variable 'x' should reflect the state of the check button, and viceversa,
if I change the value of x, from 0 to 1, the widget reflects the change.
Well, in practice, I get a constant zero, whether I click or not the
checkbutton. I must be missing something, but I can;t figure out what it
is. Any comments will be welcome.

TIA,
Gerardo




More information about the Tkinter-discuss mailing list