[Tkinter-discuss] Checkbutton variable type

Michael Lange klappnase at web.de
Wed Aug 29 10:37:05 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.
> 

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" .

Michael


More information about the Tkinter-discuss mailing list