Is it possible to call a function from a Tkinter widget.bind and include args???
Martin v. Loewis
martin at v.loewis.de
Mon Feb 11 16:58:39 EST 2002
"G. Willoughby" <sab at NOSPAM.freeuk.com> writes:
> 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???
The common idiom is
Button1.bind("<Enter>", lambda ev:printButtonAndCoords(ev,"button1"))
Button2.bind("<Enter>", lambda ev:printButtonAndCoords(ev,"button2"))
Notice that event.widget will give you the widget that was the source
of the event, so you may not need additional parameters at all.
Regards,
Martin
More information about the Python-list
mailing list