[Tutor] Passing user defined variables to mouseclick/enter/leave events

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue May 27 14:52:02 2003


On Tue, 27 May 2003, Python-lover wrote:

> hi, I am using python and tkinter. Is it possible to pass user defined
> variables to and event that bind to mouse enter ("Enter" ) event.

Hello!


Sure; it should work ok.


> I want to pass some data to the event which is bound to "Enter" event.

Ok, let's take a look.



###
self.canvas.tag_bind('movex1',"<Enter>",
          lambda type=1, xy=1:
          self.ChangeCursor(type,xy))
###

This would look ok, except that I'm not too familiar with tag_bind.
Doesn't the function need to account for the even object that's passed
over?


The second call to tag_bind looks better:

###
self.canvas.tag_bind('movey1',"<Enter>",
                     lambda event,type=1, xy=2:
                     self.ChangeCursor(type,xy))
###

but it still needs to send that event over to ChangeCursor as a parameter.


Try:


###
self.canvas.tag_bind('movex1',"<Enter>",
                     lambda event, type=1, xy=1:
                         self.ChangeCursor(event, type, xy))
self.canvas.tag_bind('movey1',"<Enter>",
                     lambda event, type=1, xy=2:
                         self.ChangeCursor(event, type, xy))
###




Hope this helps!