tkinter: Passing arguments when binding keys to functions
Antonio Cuni
cuniREMOVE_THIS at programmazione.it
Fri Jan 10 13:09:39 EST 2003
Tim Daneliuk wrote:
> for x in range(len(array)):
> y = array[x]
> widget.bind('<F' + str(x+1) + '>', lambda arg=y : CommonHandler(arg))
>
> Is this general approach valid?
I usually use something like this:
def make_handler(arg)
def handler():
print arg
return handler
widget.bind('<F1>', make_handler(arg))
I think it's clearer than his lambda cousin, but they should be
equivalent.
ciao Anto
--
"Computer science is not about computers any more than astronomy
is about telescopes." -- EW Dijkstra
More information about the Python-list
mailing list