How to pass a parameter with an event binding?

Alec Bennett whatyoulookin at yahoo.com
Sun Dec 9 02:37:41 PST 2007


I can't figure out how to pass a parameter with my
event binding. For example, suppose I want to pass the
name of the button that was just clicked. Normally I'd
do this:

self.button1 = wx.Button(panel, -1, label="Start")

self.Bind(wx.EVT_BUTTON, self.OnStart,
id=self.button1.GetId())

def OnStart(self, event):
....print "pressed!"


However, what if I wanted to pass a paramter to my
OnStart function. This is the gist of what I want to
do, but this doesn't work. Note the addition of the
"something" variable:

self.button1 = wx.Button(panel, -1, label="Start")

self.Bind(wx.EVT_BUTTON, self.OnStart("something"),
id=self.button1.GetId())

def OnStart(self, event, myvar):
....print myvar

> TypeError: OnStart() takes exactly 3 arguments (2
given)

Any tips on this?









      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping




More information about the wxpython-users mailing list