Pythonで一定間隔で処理を実行する例をもう一つ見つけた。
ただし,.NETが使用できる場合には.NETのTimerの方がよいと思う。
今度はwxWidgetが使用できる場合の例
まず,pip install wxpythonをインストールする。
そしてサンプルコード
import wx
from datetime import datetime
from time import sleep
class TestApp(wx.App):
def TimerStart(self):
self.t1 = wx.Timer(self)
self.t1.Start(1000)
def TimerStop(self):
self.t1.Stop()
print('end')
del self.t1
def TimerTest(self, event):
print(datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
def OnInit(self):
self.Bind(wx.EVT_TIMER, self.TimerTest)
self.TimerStart()
return True
app = TestApp()
app.MainLoop()
ただし,タイマーの止め方はわからない。IDLEなどを使用していると,タイマーが止まらず回りっぱなしになってしまう。
タグ:Python

