Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import time
  2. import wx
  3.  
  4. ########################################################################
  5. class MyFrame(wx.Frame):
  6. """"""
  7.  
  8. #----------------------------------------------------------------------
  9. def __init__(self):
  10. """Constructor"""
  11. wx.Frame.__init__(self, None, title='Static Example')
  12. panel = wx.Panel(self)
  13. self.counter = 10
  14.  
  15. font = wx.Font(24, wx.FONTFAMILY_ROMAN,
  16. wx.FONTSTYLE_NORMAL,
  17. wx.FONTWEIGHT_BOLD)
  18.  
  19. self.lbl = wx.StaticText(panel, label='10')
  20. self.lbl.SetFont(font)
  21.  
  22. btn = wx.Button(panel, label='Start Countdown')
  23. btn.Bind(wx.EVT_BUTTON, self.start)
  24.  
  25. self.timer = wx.Timer(self)
  26. self.Bind(wx.EVT_TIMER, self.update, self.timer)
  27.  
  28. sizer = wx.BoxSizer(wx.VERTICAL)
  29. sizer.Add(self.lbl, 0, wx.ALL, 5)
  30. sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
  31. panel.SetSizer(sizer)
  32.  
  33. self.Show()
  34.  
  35. def start(self, event):
  36. self.timer.Start(2000)
  37.  
  38. def update(self, event):
  39. if self.counter == 0:
  40. self.timer.Stop()
  41. self.lbl.SetLabel('KA-BOOM!')
  42. return
  43. else:
  44. self.counter -= 1
  45.  
  46. self.lbl.SetLabel(str(self.counter))
  47.  
  48.  
  49. if __name__ == '__main__':
  50. app = wx.App(False)
  51. frame = MyFrame()
  52. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement