This paper describes the simple application of Wxpython timer Wx.timer. Share to everyone for your reference. Specific as follows:
#-*-Coding:utf-8-*-######################################################## # # This is a simple application of Wxpython timer Wx.timer # # 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. The Timer (self) is #创建定时器 self. Bind (WX. Evt_timer, self. OnTimer, Self.timer) #绑定一个定时器事件 def __del__ (self): Pass # Virtual event handlers, overide them in your derived CL OnStart (self, event): Self.timer.Start (+) #设定时间间隔为1000毫秒, and start Timer def OnStop (self, event): Self.ti Mer. Stop () def OnTimer (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 is automatically created using Wxformbuilder ######################################################## if __name__== ' __main__ ': app = wx. Pysimpleapp () frame = MyFrame1 (None) frame. Show () app. Mainloop () ########################################################
The effect of the operation is as follows:
Hopefully this article will help you with Python programming.