Is it possible to call a function from a Tkinter widget.bind and include args???

G. Willoughby sab at NOSPAM.freeuk.com
Tue Feb 12 23:22:22 CET 2002


Thankyou all, your comments are very helpful!   :)   Especially the
GenericCallback class!

G. Willoughby


"G. Willoughby" <sab at NOSPAM.freeuk.com> wrote in message
news:a4995n$gbg$1 at news5.svr.pol.co.uk...
> Is it possible to call a function from a Tkinter widget.bind and include
> args???
> i.e. i want to do something like this:
>
> def printButtonAndCoords(event, button):
>     print "you rolled over %s and coords are %d:%d" % button, event.x,
> eventy
>
> Button1.bind("<Enter>", printButtonAndCoords("button1"))
> Button2.bind("<Enter>", printButtonAndCoords("button2"))
>
> is this possible???
>
> i have tried this: but it seems a bit crap!:
>
> [snip]
> ...
>   self.newFileButton.bind("<Enter>", self.getMouseCoords)
>   self.newFileButton.bind("<Leave>", self.deleteToolTip)
> ...
>  def getMouseCoords(self, event):
>   self.xPos=event.x_root-5
>   self.yPos=event.y_root+5
>   self.showToolTip(str(event.widget), self.xPos, self.yPos)
>
>  def showToolTip(self, id, xPos, yPos):
>   if id==".8387596.7951612": #this looks very breakable!
>    self.toolTip=tkToolTip.toolTip(xPos, yPos, liftAbove=self.master,
> text="Create a new file")
>
>  def deleteToolTip(self, event):
>   self.toolTip.destroyToolTip()
>   del self.toolTip
> [/snip]
>
> help...  :'-(
>
> G. Willoughby
>
>
>
>





More information about the Python-list mailing list