tkinter prob

Eric Brunel eric_brunel at despammed.com
Mon Aug 21 03:30:42 EDT 2006


On Mon, 21 Aug 2006 08:50:29 +0200, JyotiC <jyoti.chhabra at gmail.com> wrote:

> i have tried it out but it's not working.
> this is the code
>
> from Tkinter import *
>
> class abc:
>     def __init__(self,parent):
>         #make container myparent
>         self.myparent=parent
>         self.myparent.geometry("500x200")
>
>         #make the initial frame
>         self.frame=Frame(self.myparent)
>         self.frame.pack()
>
>         self.var=IntVar()
>         self.var.set(0)
>
>         a=Button(self.frame,text="button")
>         a.pack()
>
>
> Checkbutton(self.frame,text="hello",variable=self.var,command=self.com(a)).pack()

This *calls* self.com(a) and assigns its *results* (which happens to be  
None) to the command option in your button. So your button does nothing.

To do what you want, use:

          self.a = Button(self.frame,text="button")
          self.a.pack()
          Checkbutton(self.frame,text="hello",variable=self.var,command=self.com).pack()

in __init__, then:

      def com(self):
          if self.var.get()==1:
              self.a.config(state=ENABLED)
          else:
              self.a.config(state=DISABLED)

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"



More information about the Python-list mailing list