Wxpython Timer Wx.timer Simple Application Example

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.