WxPython Timer wx. Timer simple application example

Source: Internet
Author: User
This article mainly introduces the wxPython timer wx. simple Timer application. The example analyzes how to use Python to create a window application and Timer using wxPython. If you need it, refer to the following example to describe the wxPython Timer wx. simple Timer application. Share it with you for your reference. The details are as follows:

#-*-Coding: UTF-8 -*-#################################### ###################### this is the wxPython timer wx. simple Timer 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 "timer test applet", 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 a timer self. timer = wx. timer (self) # create a Timer self. bind (wx. EVT_TIMER, self. onTimer, self. timer) # bind a timer event def _ del _ (self): pass # Virtual event handlers, overide them in your derived class def OnStart (self, event): self. timer. start (1000) # set the time interval to 1000 milliseconds and Start the timer def OnStop (self, event): self. timer. stop () def OnTimer (self, evt): # display the time event processing function t = time. localtime (time. time () StrYMDt = time. strftime ("% Y-% B-% d", t) self. setStatusText (StrYMDt, 0) # display StrIMSt = time. strftime ("% I: % M: % S", t) self. setStatusText (StrIMSt, 1) # display time ##################################### ##################### the preceding interface code is automatically created using wxFormBuilder ############ ######################################## #### if _ name __= = '_ main __': app = wx. pySimpleApp () frame = MyFrame1 (None) frame. show () app. mainLoop () ######################################## ################

The running effect is as follows:

I hope 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.