[Tutor] Checkbox problem in Tkinter

Peter Otten __peter__ at web.de
Mon Jan 10 12:01:46 CET 2011


ANKUR AGGARWAL wrote:

> and i got the output as -
> [image: Screenshot.png]

The image doesn't survive.
 
> When i take the var as of string variable type i am  unable to edit the
> checkbox. It comes slected predefined and the widget in kindof Invisible
> and
> u can say uneditable. Can anybody tell me whats i am  doing wrong in
> this??? Its works fine if i take the var variable as the integer variable.
> I can deselect and select in that case and it gives me the desired result
> but in string case i am unable to do so as checkbox is invisible type.
> I am using Python 2.6

I can't reproduce that behaviour. The widget appears greyed initially, but 
is still editible. You could try to initialise the StringVar with onvalue or 
offvalue:

> from Tkinter import *
> root=Tk()
> var=StringVar()

  var.set("hhhh")

> c=Checkbutton(root,text="hello",variable=var,onvalue="hhhh",
> offvalue="gggg")
> c.pack()
> root.mainloop()




More information about the Tutor mailing list