steve2
August 7, 2014, 3:48pm
1
Hi,
Suppose you have a wx.Choice widget, you bind a function to it:
self.my_choice = wx.Choice(self, -1, choices=[“a”,“b”])
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.my_choice )
But I also want to pass an argument to “OnTypeChoice” function, when binding it,
def OnTypeChoice(self, evt, my_argument):
cb = evt.GetEventObject()
index = cb.GetCurrentSelection()
label = cb.GetString(index)
print "my_argument: ", my_argument
How should I change the Bind statement below to achieve this?
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.my_choice )
Paul6
August 7, 2014, 4:12pm
2
self.Bind(wx.EVT_CHOICE, lambda event: self.OnTypeChoice(event,
"my_argument"), self.my_choice)
That should work
···
On 7 August 2014 16:48, steve <oslocourse@gmail.com> wrote:
Hi,
Suppose you have a wx.Choice widget, you bind a function to it:
self.my_choice = wx.Choice(self, -1, choices=["a","b"])
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.my_choice )
But I also want to pass an argument to "OnTypeChoice" function, when binding
it,
def OnTypeChoice(self, evt, my_argument):
cb = evt.GetEventObject()
index = cb.GetCurrentSelection()
label = cb.GetString(index)
print "my_argument: ", my_argument
How should I change the Bind statement below to achieve this?
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.my_choice )
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout .
In addition to what Paul mentioned, see Passing Arguments to Callbacks - wxPyWiki . It has a couple of other interesting examples that you might find helpful.
···
On Thursday, August 7, 2014 10:48:14 AM UTC-5, steve wrote:
Hi,
Suppose you have a wx.Choice widget, you bind a function to it:
self.my_choice = wx.Choice(self, -1, choices=[“a”,“b”])
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.my_choice )
But I also want to pass an argument to “OnTypeChoice” function, when binding it,
def OnTypeChoice(self, evt, my_argument):
cb = evt.GetEventObject()
index = cb.GetCurrentSelection()
label = cb.GetString(index)
print "my_argument: ", my_argument
How should I change the Bind statement below to achieve this?
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.my_choice )
Very cool, I need to read more on the lambda stuff!