[Tkinter-discuss] IntVar() not being attached to Checkbutton

Adam Kadzban akadzban at iit.edu
Wed Jun 10 22:19:14 CEST 2009


Hi, I'm having some problems with my Checkbuttons.  I'm giving them IntVars
to bind to, but there seems to be no relationship between the IntVars and
the buttons.  This is the first time I've had problems with this, I've used
IntVars with Checkbuttons in the past with no such trouble.

I have the main part of the GUI (which has Checkbuttons that behave
normally), with a menu option to create another window for some "advanced
options".  The code for this window is in its own class, which takes a list
of options as parameters and then has some check boxes and entry boxes so
you can change the option list.  Here's the relevant code:

...
self.tVar = IntVar()
...
self.tempbutton =
Checkbutton(self.tophalf,variable=self.tVar,text="Calculate temperature")
...

When I try the program with this code, I can check/uncheck the boxes, but
tVar never change (I printed out their values, they stay 0).  I also tried
coding in button selection (e.g. self.tempbutton.select()), but tVar never
changes.

I also tried making some functions, and binding them to the checkbutton:
self.tempbutton =
Checkbutton(self.tophalf,variable=self.tVar,text="Calculate
temperature",command=self.checkTemp)
...
def checkTemp(self):
    if self.tVar.get() == 1:
        self.tempbutton.select()
    else:
        self.tempbutton.deselect()
...
Having that, though, doesn't let me "check" the button (I'm guessing because
tVar never gets set to 1, it always goes to deselect).

Anyone have any ideas why this is happening?  I've been banging my head
against a wall here, and I rewrote the whole class thinking maybe it was
something funny with scoping, but as far as I can tell everything is ok.  I
must be missing something...

Thanks,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20090610/3e09f388/attachment.htm>


More information about the Tkinter-discuss mailing list