[Tkinter-discuss] Checkbutton variable type

Bob Greschke bob at passcal.nmt.edu
Wed Aug 29 22:30:11 CEST 2007

> On Tue, 28 Aug 2007 13:30:02 -0600
> Bob Greschke <bob at passcal.nmt.edu> wrote:
>> The Checkbutton widget
>> Var = IntVar()
>> Checkbutton(Frm, text = "Destroy", variable = Var)
>> wants Var to be an IntVar, but it also works if Var is a StringVar
>> and you set() Var to "0" and "1".  Is there a possibility that this
>> will be "fixed" some time in the future, or would it be safe to keep
>> Var as a StringVar, or is it not even really broken (I don't know  
>> Tcl/
>> Tk which I assume is allowing this?)?  In my case it would be nice to
>> keep "0" or "1" in a MySQL database column and have a Tkinter form
>> with a Checkbutton do the right thing without having to change the
>> column to an int, or keep converting back and forth between chars and
>> ints for that one column to keep from running into trouble in the
>> future.
> On Aug 29, 2007, at 02:37, Michael Lange wrote:
> Hi Bob,
> I am not a tcler myself, but I think the integers are being  
> converted to strings
> anyway when they are passed to tcl, so 1 and "1" might be  
> equivalent here.
> If you want to be even more safe, you might want to use the  
> checkbutton's
> onvalue and offvalue options, like onvalue="1", offvalue="0" .

onvalue?! offvalue??!!  Every time I look in Grayson's Python and  
Tkinter programming I DON'T see something. :)  I never even knew  
those existed and I must have looked at that section 100 times over  
the years.  Thanks!


More information about the Tkinter-discuss mailing list