tkinter: Passing arguments when binding keys to functions
Abel Daniel
abli at freemail.hu
Fri Jan 10 14:27:52 EST 2003
Tim Daneliuk (tundra at tundraware.com) wrote:
[...snipped...]
> 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
abli at freemail.hu
More information about the Python-list
mailing list