newbie: binding args in callbacks

Edward K. Ream edream at tds.net
Wed Jul 10 09:54:53 EDT 2002


This question was asked a while back, and I don't see it in the FAQ or
in the archives...

I would like to create a set of Tkinter callbacks that vary only in the
bindings of a single argument. For example,  I would like to do:

for val in vals:
  b = Tk.Button(...,command=self.myCallback(val))

But this doesn't work: it executes callback, rather than returning the
callback function with the second arg bound to val.

I also tried:

for val in vals:
 callback=lambda None:self.myCallback(x=val)
 b = Tk.Button(...,command=callback)

But that doesn't quite work either.  When the callback executes I get:
TypeError: <lambda>() takes exactly 1 argument (0 given)

Can someone explain how to do this?  Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------



More information about the Python-list mailing list