Here is a runnable example that works on Windows 7, Python 2.6, wx 2.8.
import wx
class ListTest(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(380, 230))
panel = wx.Panel(self, -1)
self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT)
self.list.InsertColumn(0, 'col 1', width=140)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.list, 1, wx.EXPAND)
panel.SetSizer(hbox)
self.Centre()
self.Show(True)
self.Bind(wx.EVT_CHAR_HOOK, self.onKey)
def onKey(self, evt):
if evt.GetKeyCode() == wx.WXK_DOWN:
self.list.InsertStringItem(0, "level 1")
self.list.InsertStringItem(1, "level 2")
self.list.SetBackgroundColour(wx.RED)
self.list.Refresh()
print self.list.GetItemText(0)
print self.list.GetItemText(1)
else:
evt.Skip()
app = wx.App()
ListTest(None, 'list test')
app.MainLoop()
volting
2010-08-26 21:41:54