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

G. Willoughby sab at NOSPAM.freeuk.com
Mon Feb 11 15:23:50 EST 2002


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