using lambda to pass args to event function

Christian Kristukat ckkart at hoc.net
Tue Jan 2 05:03:20 PST 2007


Hi Christopher,

Christopher Barker <Chris.Barker <at> noaa.gov> writes:
> 
> Ben North wrote:
> >> def makeArgsHandler(handler, arg):
> >>      return lambda event: handler(event, arg)
> 
> >    from functional import rcurry
> >    self.Bind(wx.EVT_BUTTON,
> >              rcurry(controller.PopulateMainList, 'pkl'),
> >              id = ID_PKL_BUTTON)
> 
> pretty cool.
> 
> however, for an example this simple, you may be able to make use us 
> default arguments:
> 
>      self.Bind(wx.EVT_BUTTON,
>                lambda event: handler(event, arg=current_arg),
>                id = ID_PKL_BUTTON)
> 
> now arg will get set to whatever current_arg is when that Bind call is 
> executed -- i.e. in the Window __init__, usually.

I found this old posting where you presented a way to pass arguments 
along with the event object to an event handler.
That does not work, at least with python 2.4 on linux. When you put the call
to Bind in a loop the event handler always receives the last value of 
current_arg of the loop. Are you sure this should work?

Christian







More information about the wxpython-users mailing list