[Tutor] Tkinter

Abel Daniel abli@freemail.hu
Thu Dec 5 04:55:01 2002


 Hans Gubitz (gubitz@netcologne.de) wrote:
> My Tkinter.Button is an attribute in the class person. In the
> Application I want to get the instance of person, button is belonging
> to.
> 
> My workaround is the function holePerson. Is this the way you do it in
> Python?
> 
I have two ideas:
- subclass Tkinter.Button. I think that way the callback will get
your new, modified class as event.widget .

- intercept the callback when it is called, for example like this:
(not tested)
> class person:
>     def __init__(self,master,bild,r,c,callback):
>         self.bild = bild
>         self.button = Tkinter.Button(master,text=self.bild)
>         self.button.grid(row = r, column = c)
          self.button.bind('<Button-1>',self._callback)
          self.callback=callback
          
     def _callback(self, event):
          event.widget=self
          apply(self.callback, event)

[... rest of code snipped ....]

abli
abli@freemail.hu