[Tkinter-discuss] IntVar() not being attached to Checkbutton
Adam Kadzban
akadzban at iit.edu
Wed Jun 10 23:05:58 CEST 2009
On Wed, Jun 10, 2009 at 3:50 PM, Michael Lange <klappnase at web.de> wrote:
> Hi Adam,
>
> On Wed, 10 Jun 2009 15:19:14 -0500
> Adam Kadzban <akadzban at iit.edu> wrote:
>
> (...)
> > 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 cannot reproduce this here, maybe it depends on the OS or the Tk
> version in use. Just a guess: have you tried to explicitely define
> onvalue=1 and offvalue=0 in the Checkbutton constructor ?
>
> Michael
I'm on Ubuntu 9.04, with Python 2.5.2 and the latest version of python-tk,
at least according to aptitude. And yes, I've tried that, didn't work.
Adam
>
>
> >
> > 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
> >
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20090610/c4b1b092/attachment.htm>
More information about the Tkinter-discuss
mailing list