Created
August 19, 2016 20:01
-
-
Save driscollis/447c39b36d1acac1674c0dc59c5d7515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import wx | |
| import time | |
| class MyForm(wx.Frame): | |
| def __init__(self): | |
| wx.Frame.__init__(self, None, wx.ID_ANY, "Timer Tutorial 1", | |
| size=(500,500)) | |
| panel = wx.Panel(self, wx.ID_ANY) | |
| self.timer = wx.Timer(self) | |
| self.Bind(wx.EVT_TIMER, self.update, self.timer) | |
| self.toggleBtn = wx.Button(panel, wx.ID_ANY, "Start") | |
| self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle) | |
| def onToggle(self, event): | |
| btnLabel = self.toggleBtn.GetLabel() | |
| if btnLabel == "Start": | |
| print "starting timer..." | |
| self.timer.Start(1000) | |
| self.toggleBtn.SetLabel("Stop") | |
| else: | |
| print "timer stopped!" | |
| self.timer.Stop() | |
| self.toggleBtn.SetLabel("Start") | |
| def update(self, event): | |
| print "\nupdated: ", | |
| print time.ctime() | |
| # Run the program | |
| if __name__ == "__main__": | |
| app = wx.App(False) | |
| frame = MyForm().Show() | |
| app.MainLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment