• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

python 搞代码 4年前 (2022-01-08) 23次浏览 已收录 0个评论

这篇文章主要介绍了wxPython定时器wx.Timer简单应用,实例分析了Python使用wxPython创建窗口应用程序及定时器的相关使用技巧,需要的朋友可以参考下

本文实例讲述了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.Ti<p style="color:transparent">来源gao!%daima.com搞$代*!码$网</p>mer(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() ######################################################## 

运行效果如下所示:

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

以上就是wxPython定时器wx.Timer简单应用实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:wxPython定时器wx.Timer简单应用实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址