[wxPython-users] buttond.Bind() and args

Charl P. Botha cpbotha at cpbotha.net
Mon Jul 31 03:12:03 PDT 2006


On 7/31/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
> Timothy Smith <timothy at open-networks.net> wrote:
> > if i'm calling pourDrink via  Button1.Bind(wx.EVT_BUTTON,pourDrink)
> > how can i pass etc arguments to pourDrink? eg. pourDrink(db)
>
> Create a class...
>
> class caller:
>     def __init__(self, fcn, *args):
>         self.fcn = fcn
>         self.args = args
>     def __call__(self, evt):
>         return self.fcn(*args)
>
> Button1.Bind(wx.EVT_BUTTON, caller(pourDrink, db))

Or just use a lambda (unnamed function), it's far compact, warts or no warts:

Button1.Bind(wx.EVT_BUTTON, lambda e: pourDrink(db))




More information about the wxpython-users mailing list