Reading about Python? Actually practice it. Try PyChallenge free

Pythonspot

wxPython Buttons

Adding buttons and binding click events in wxPython is done using wx.Button and EVT_BUTTON.

wxPython Button Example

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(parent=None, title="wxPython Buttons", size=(350, 200))
        panel = wx.Panel(self)
        
        self.btn = wx.Button(panel, label="Click Me", pos=(120, 60))
        self.btn.Bind(wx.EVT_BUTTON, self.on_click)
        
    def on_click(self, event):
        wx.MessageBox("Button was clicked!", "Information", wx.OK | wx.ICON_INFORMATION)

app = wx.App()
frame = MyFrame()
frame.Show()
app.MainLoop()

Back to GUI Programming Hub →