Home Backend Development Python Tutorial wxPython定时器wx.Timer简单应用实例

wxPython定时器wx.Timer简单应用实例

Jun 10, 2016 pm 03:10 PM
wxpython timer

本文实例讲述了wxPython定时器wx.Timer简单应用。分享给大家供大家参考。具体如下:

# -*- coding: utf-8 -*-  
######################################################## 
## 这是wxPython定时器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"测试定时器的小程序", 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"启动定时器", wx.DefaultPosition, wx.DefaultSize, 0 ) 
    gSizer1.Add( self.m_btnStart, 0, wx.ALL, 5 ) 
    self.m_btnStop = wx.Button( self, wx.ID_ANY, u"停止定时器", 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 ) 
    # 创建定时器 
    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毫秒,并启动定时器 
  def OnStop( self, event ): 
    self.timer.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)#显示时间 
######################################################## 
## 以上界面代码使用wxFormBuilder自动创建 
######################################################## 
if __name__=='__main__': 
  app = wx.PySimpleApp() 
  frame = MyFrame1(None) 
  frame.Show() 
  app.MainLoop() 
######################################################## 

Copy after login

运行效果如下所示:

希望本文所述对大家的Python程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set a timer on your iPhone camera How to set a timer on your iPhone camera Apr 14, 2023 am 10:43 AM

How long can you set a timer on your iPhone camera? When you access the timer options in the iPhone's camera app, you'll be given the option to choose between two modes: 3 seconds (3s) and 10 seconds (10s). The first option lets you take a quick selfie from the front or rear camera while you're holding your iPhone. The second option is useful in scenes where you can mount your iPhone on a tripod from a distance to click group photos or selfies. How to Set a Timer on an iPhone Camera While setting a timer on an iPhone camera is a fairly simple process, exactly how to do it varies depending on the iPhone model you're using.

Python GUI programming: Get started quickly and easily create interactive interfaces Python GUI programming: Get started quickly and easily create interactive interfaces Feb 19, 2024 pm 01:24 PM

A brief introduction to python GUI programming GUI (Graphical User Interface, graphical user interface) is a way that allows users to interact with computers graphically. GUI programming refers to the use of programming languages ​​to create graphical user interfaces. Python is a popular programming language that provides a rich GUI library, making Python GUI programming very simple. Introduction to Python GUI library There are many GUI libraries in Python, the most commonly used of which are: Tkinter: Tkinter is the GUI library that comes with the Python standard library. It is simple and easy to use, but has limited functions. PyQt: PyQt is a cross-platform GUI library with powerful functions.

What is java timer expression What is java timer expression Dec 27, 2023 pm 05:06 PM

The timer expression is used to define the execution plan of the task. The timer expression is based on the model of "execute a task after a given time interval". The expression usually consists of two parts: an initial delay and a time interval.

How to implement the timer function in the Workerman document How to implement the timer function in the Workerman document Nov 08, 2023 pm 05:06 PM

How to implement the timer function in the Workerman document Workerman is a powerful PHP asynchronous network communication framework that provides a wealth of functions, including the timer function. Use timers to execute code within specified time intervals, which is very suitable for application scenarios such as scheduled tasks and polling. Next, I will introduce in detail how to implement the timer function in Workerman and provide specific code examples. Step 1: Install Workerman First, we need to install Worker

Python GUI Programming: Make your programs stand out Python GUI Programming: Make your programs stand out Feb 19, 2024 pm 08:33 PM

Introduction to pythonGUI programming PythonGUI programming, that is, graphical user interface programming, is the process of creating application program interfaces using the Python language. GUI applications usually have elements such as windows, buttons, text boxes, menus, etc., through which users can interact with the program. Python GUI programming has many benefits. First, it can make your program more beautiful and easier to use. Secondly, it can make your program cross-platform, that is, it can run on different operating systems. Third, it can make your program more flexible and easier to extend. Commonly used Python GUI libraries In Python, there are many commonly used GUI libraries, including Tkinter, PyQt, wxPython and PyG

How to set a timer for daily scheduled task execution in Java? How to set a timer for daily scheduled task execution in Java? Dec 27, 2023 am 11:10 AM

Java timer: How to set a scheduled execution task every day? In daily Java development, we often encounter the need to perform a certain task regularly every day. For example, perform a data backup task at 1 a.m. every day, or send a daily email at 8 p.m., etc. So in Java, we can use timers to achieve such a function. Java provides a variety of timer implementation methods. This article will introduce two methods based on Timer and ScheduledExecutorService.

Detailed explanation of the GUI library wxPython in Python Detailed explanation of the GUI library wxPython in Python Jun 09, 2023 pm 10:00 PM

Python is a concise, easy to learn, and efficient programming language. It is widely used in various fields such as data science, artificial intelligence, game development, network programming, etc. Although Python comes with some GUI libraries, their functions are relatively simple and cannot meet the needs of various complex applications. Therefore, there are many GUI libraries to choose from in Python, among which wxPython is one of them, which this article will introduce in detail. Introduction to wxPython wxPython is an open source, cross-platform GUI library based on

The Art of Python GUI Programming: Creating Beautiful and Easy-to-Use Interfaces The Art of Python GUI Programming: Creating Beautiful and Easy-to-Use Interfaces Feb 19, 2024 pm 05:36 PM

PythonGUI programming, as the name suggests, is a programming technology that uses the Python language to create a graphical user interface (GUI). Python GUI programming has many advantages, such as: cross-platform, rich third-party library support, concise syntax, etc. Therefore, Python GUI programming is deeply loved by programmers and is widely used in various types of application development. In Python GUI programming, the most commonly used third-party libraries are Tkinter, PyQt and wxPython. Tkinter is part of the Python standard library and is simple and easy to use, but has limited functionality. PyQt and wxPython are both powerful third-party GUI libraries, but they are also more

See all articles