May-31-2022, 05:39 PM
To be able to have a pointer to the button object in the event handler method
Then you can use the buttons
on_press
you need to add self.
to the front of my_btn
in the __init__
method.Then you can use the buttons
SetLabel
method.import wx class MyFrame(wx.Frame): def __init__(self): super().__init__(parent=None, title="Hello World") panel = wx.Panel(self) my_sizer = wx.BoxSizer(wx.VERTICAL) self.my_btn = wx.Button(panel, label="Press Me") self.my_btn.Bind(wx.EVT_BUTTON, self.on_press) my_sizer.Add(self.my_btn, 0, wx.ALL | wx.CENTER, 5) panel.SetSizer(my_sizer) self.Show() def on_press(self, event): self.my_btn.SetLabel("New Value") if __name__ == "__main__": app = wx.App() frame = MyFrame() app.MainLoop()