ListCtrl in wxpython
How to use timer with ListCtrl??(i want to clear all items in Li开发者_开发百科st then add items in List to every 2 second ...)
Here's a simple example:
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()
精彩评论