Wxpython Timer Wx.timer Simple Application Example

Source: Internet
Author: User
Tags bind

The example of this paper describes the simple application of Wxpython timer Wx.timer. Share to everyone for your reference. Specifically as follows:

?

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 () ########################################################

The results of the operation are as follows:

I hope this article will help you with your 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.