RosettaCodeData/Task/Simple-windowed-application/Python/simple-windowed-application-4.py

36 lines
1,019 B
Python
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
import wx
2019-09-12 10:33:56 -07:00
class ClickCounter(wx.Frame):
def __init__(self):
super().__init__(parent=None)
self.count = 0
self.button = wx.Button(parent=self,
label="Click me!")
self.label = wx.StaticText(parent=self,
label="There have been no clicks yet")
self.Bind(event=wx.EVT_BUTTON,
handler=self.click,
source=self.button)
2013-04-11 01:07:29 -07:00
2019-09-12 10:33:56 -07:00
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(window=self.button,
proportion=1,
flag=wx.EXPAND)
self.sizer.Add(window=self.label,
proportion=1,
flag=wx.EXPAND)
self.SetSizer(self.sizer)
self.sizer.Fit(self)
2013-04-11 01:07:29 -07:00
2019-09-12 10:33:56 -07:00
def click(self, _):
self.count += 1
self.label.SetLabel(f"Count: {self.count}")
2013-04-11 01:07:29 -07:00
2019-09-12 10:33:56 -07:00
if __name__ == '__main__':
app = wx.App()
frame = ClickCounter()
frame.Show()
app.MainLoop()