tkinter: Passing arguments when binding keys to functions

Abel Daniel abli at
Fri Jan 10 20:27:52 CET 2003

Tim Daneliuk (tundra at wrote:
> for x in range(len(array)):
>     y = array[x]	
>     widget.bind('<F' + str(x+1) + '>', lambda arg=y : CommonHandler(arg))
[...more snipped...] 
> So, I guess the heart of my question becomes, "Why does this formulation
> pass the event object, not the array member to CommonHandler()>"
Because the callback will get the event object as a parameter. (And that
overwrites the default argument.)

you need:
     widget.bind('<F' + str(x+1) + '>', lambda e, arg=y : CommonHandler(arg))

abli at

More information about the Python-list mailing list