tkinter: Passing arguments when binding keys to functions
abli at freemail.hu
Sat Jan 11 00:39:44 CET 2003
Tim Daneliuk (tundra at tundraware.com) wrote:
> Aha! That explains it. There is a minor error in your example, I believe.
> Shouldn't the code be:
> widget.bind('<F' + str(x+1) + '>', lambda e, arg=y : CommonHandler(e, arg))
If you need the event object (i.e. the data it contains, like
event.widget, etc.) then you need to pass it in as you wrote.
However, it is not mandatory. If CommonHandler looks like:
# or popup a modal dialog asking wheter the user wants to quit
# i.e. doing something for which event data is not needed
then its not needed.
(I assumed you didnt want to change CommonHandler : ) )
More information about the Python-list