Best way to get the name of a button that called an event?

前端 未结 7 1207
北荒
北荒 2021-01-03 05:26

In the following code (inspired by this snippet), I use a single event handler buttonClick to change the title of the window. Currently, I need to evaluate if t

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 05:46

    You could give the button a name, and then look at the name in the event handler.

    When you make the button

    b = wx.Button(self, 10, "Default Button", (20, 20))
    b.myname = "default button"
    self.Bind(wx.EVT_BUTTON, self.OnClick, b)
    

    When the button is clicked:

    def OnClick(self, event):
        name = event.GetEventObject().myname
    

提交回复
热议问题