主要介绍下 时间的定时, 还有计数的定时
#!/usr/bin/python
#-*- coding:utf8 -*-import wx
import time
class MyFrame(wx.Frame):
def __init__(self, root):
wx.Frame.__init__(self, root, -1, u"定时器示例", size=(400,400))
panel = wx.Panel(self, -1)
#self.count = 0
#self.timer = wx.PyTimer(self.Notify)
#self.timer.Start(1000)
self.inputText = wx.TextCtrl(panel, -1, "", pos=(10,10), size=(200,50))
self.inputText2 = wx.TextCtrl(panel, -1, "", pos=(20,10), size=(200,50))
self.count = 0
self.timer = wx.PyTimer(self.Notify)
self.timer.Start(1000)
self.startBtn = wx.Button(panel, -1, u"开始")
self.endBtn = wx.Button(panel, -1, u"停止")
self.Bind(wx.EVT_BUTTON, self.OnStart, self.startBtn)
self.Bind(wx.EVT_BUTTON, self.OnEnd, self.endBtn)
sizer = wx.FlexGridSizer(cols=1, hgap=10, vgap=10)
sizer.Add(self.inputText)
sizer.Add(self.inputText2)
sizer.Add(self.startBtn)
sizer.Add(self.endBtn)
panel.SetSizer(sizer)
panel.Fit()
def OnStart(self, event):
self.timer2 = wx.CallLater(1000, self.OnCallTimer, 1,2,3)
def OnEnd(self, event):
self.timer2.Stop()
self.inputText2.Value = str(self.count)
del self.timer2
def OnCallTimer(self, *args, **kw):
self.count = self.count+1
self.inputText2.Value = str(self.count)
tup = args
total = 0
for x in tup:
total = total + int(x)
self.timer2.Restart(1000, total)
return total
def Notify(self):
t = time.localtime(time.time())
self.inputText.Value = time.strftime("%d-%B-%Y %I:%M:%S", t)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None)
self.frame.Show()
return True
app = MyApp()
app.MainLoop()