如何在ListCtrl中使用计时器?(我想清除List中的所有项目,然后每隔2秒在List中添加项目......)
答案 0 :(得分:4)
这是一个简单的例子:
import wx
import time
TIMER_ID = wx.NewId()
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.lstctrl = wx.ListCtrl(self, wx.ID_ANY,
size=(250,300),
style=wx.LC_REPORT)
self.lstctrl.InsertColumn(0, "Date", width=200)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.lstctrl, 1, wx.EXPAND)
self.SetSizerAndFit(sizer)
wx.EVT_TIMER(self, TIMER_ID, self.OnTimer)
self.timer = wx.Timer(self, TIMER_ID)
self.timer.Start(2000)
def OnTimer(self, event):
self.lstctrl.InsertStringItem(self.lstctrl.GetItemCount(),
time.asctime())
app=wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()