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

Josiah Carlson jcarlson at uci.edu
Mon Jul 31 00:49:11 PDT 2006


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 you could make it a method...

class obj:
    def __init__(self, db):
        self.db = db
    def pourDrink(self, evt):
        #do what you need to

Or you could attach pourDrink to any pre-existing class that has access
to your db.

Remember, this is Python, with all of the object-oriented features of
Python.

 - Josiah





More information about the wxpython-users mailing list