Надеюсь, это укажет вам правильное направление для общих методов привязки кнопки к функции обратного вызова.
#!/usr/bin/env python
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.btn = wx.Button(self, id=-1, label="One")
self.btn.Bind(wx.EVT_BUTTON, lambda event, b_name=self.btn.GetLabel(), b_id=self.btn.GetId(): self.OnButton(event, b_name, b_id) )
self.btn2 = wx.Button(self, id=-1, label="Two")
self.btn2.Bind(wx.EVT_BUTTON, self.OnButton2)
self.btn3 = wx.Button(self, id=-1, label="Three")
self.btn3.Bind(wx.EVT_BUTTON, self.OnButton3)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.btn, 0, wx.ALL, 10)
sizer.Add(self.btn2, 0, wx.ALL, 10)
sizer.Add(self.btn3, 0, wx.ALL, 10)
self.SetSizer(sizer)
self.account_type= "Deposit"
def OnButton(self, event, button_label, button_id):
print ("\nInformation provided via a Lambda")
print ("Button Pressed:", button_label, button_id)
def OnButton2(self, event):
button_label = self.btn2.GetLabel()
button_id = self.btn2.GetId()
account_type = self.account_type
print ("\nInformation provided by self.item Query")
print ("Button2 Pressed:", button_label, button_id)
print ("Value of account type:", account_type)
def OnButton3(self, event):
obj = event.GetEventObject()
button_label = obj.GetLabel()
button_id = obj.GetId()
print ("\nInformation provided via eventobject")
print ("Button3 Pressed:", button_label, button_id)
app = wx.App(False)
frame = MyFrame(None, title="Button Bind")
frame.Show()
app.MainLoop()