1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 |
#-*-Coding:utf-8-*-######################################################## # This is Wxpython timer wx.timer simple Application # # Testwxtimer1.pyw ######################################################## Import wx Import Time #################### #################################### class MyFrame1 (WX. Frame): Def __init__ (self, parent): WX. Frame.__init__ (self, parent, id = wx.id_any, title = u "Small program for Test Timer", pos = wx. defaultposition, size = wx. Size (483,155), style = WX. Default_frame_style|wx. Tab_traversal) self. Setsizehintssz (WX. DefaultSize, WX. DefaultSize) self. Setbackgroundcolour (WX. Systemsettings.getcolour (WX. Sys_colour_inactivecaptiontext)) GSizer1 = WX. Gridsizer (0, 2, 0, 0) Self.m_btnstart = wx. button (self, wx.id_any, u "Start Timer", WX. Defaultposition, WX. DefaultSize, 0 gsizer1.add (self.m_btnstart, 0, WX. All, 5) Self.m_btnstop = WX. button (self, wx.id_any, u "Stop Timer", WX. Defaultposition, WX. DefaultSize, 0 gsizer1.add (self.m_btnstop, 0, WX. All, 5) self. Setsizer (GSizer1) self. LayoUT () self.m_statusbar1 = self. Createstatusbar (2, WX. St_sizegrip, Wx.id_any) self. Centre (WX. BOTH) # Connect Events self.m_btnStart.Bind (WX. Evt_button, self. OnStart) Self.m_btnStop.Bind (WX. Evt_button, self. OnStop) # Create Timer Self.timer = WX. Timer (self) #创建定时器 self. Bind (WX. Evt_timer, self. OnTimer, Self.timer) #绑定一个定时器事件 def __del__ (self): Pass # Virtual event handlers, overide them in your derived class Def OnStart (self, event): Self.timer.Start (1000) #设定时间间隔为1000毫秒, and start Timer def OnStop (self, event): Self.timer.Stop () def Ontim ER (self, evt): #显示时间事件处理函数 t = time.localtime (Time.time ()) STRYMDT = Time.strftime ("%y-%b-%d", t) self. Setstatustext (strymdt,0) #显示年月日 strimst = Time.strftime ("%i:%m:%s", t) self. Setstatustext (strimst,1) #显示时间 ######################################################## # The above interface code uses Wxformbuilder to automatically create ######################################################## if __name__== ' __main__ ': app = WX . Pysimpleapp () frame = MyFrame1 (None) frame. Show () app. Mainloop () ######################################################## |