获取调用事件的对象

nis*_*ist 3 python events wxpython

如果我有两个对象将调用相同的方法,然后发生一个事件,是否可以看到其中哪个对象调用了该事件?

为了让它更清楚。如果我有两个按钮和一个被调用的方法,那么我会单击它们。在此方法中我可以做什么来查看单击了哪个按钮?

...
buttonA.Bind(wx.EVT_BUTTON ,self.methode)
buttonB.Bind(wx.EVT_BUTTON ,self.methode)
...
...
def methode(self,event)
  #get the button that was clicked 
Run Code Online (Sandbox Code Playgroud)

Inf*_*y77 5

尝试这个:

...
buttonA.Bind(wx.EVT_BUTTON ,self.methode)
buttonB.Bind(wx.EVT_BUTTON ,self.methode)
...
...
def methode(self, event)
  #get the button that was clicked 
  button = event.GetEventObject()

  print button.GetLabel()
Run Code Online (Sandbox Code Playgroud)