listctrl使用求解,help
各位同仁好,wxpython中对于listctrl控件,怎么选中一行,然后改变该行的颜色,希望可以给一个例子,谢谢。
[解决办法]
很详细,参看:
http://www.blog.pythonlibrary.org/2011/01/04/wxpython-wx-listctrl-tips-and-tricks/
[解决办法]
我曾经问过这个问题,有人帮忙解决了,参考一下
import wx
import wx.lib.mixins.listctrl as listmix
class TestVirtualList(wx.ListCtrl,listmix.ListCtrlAutoWidthMixin):
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, -1,
style=wx.LC_REPORT
[解决办法]
wx.LC_HRULES
[解决办法]
wx.LC_VRULES)
self.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL))
self.InsertColumn(0, "First")
self.InsertColumn(1, "Second")
self.InsertColumn(2, "Third")
self.SetColumnWidth(0, 175)
self.SetColumnWidth(1, 175)
self.SetColumnWidth(2, 175)
for i in range(10):
self.Append(('Item %d' % i, 'column %d' % i, 'thy3%d' % i))
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
def OnGetItemText(self, item, col):
prints = "Item %d, column %d" % (item, col)
return prints
def OnItemSelected(self, event):
self.currentItem = event.m_itemIndex
for i in range(self.GetItemCount()):
self.SetItemBackgroundColour(i, self.GetMainWindow().BackgroundColour)
self.SetItemState(self.currentItem, 0, wx.LIST_STATE_SELECTED)
self.SetItemBackgroundColour(self.currentItem, wx.Colour(255,255,0))
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'ListCtrl',size=(540, 350)
,style = wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER
[解决办法]
wx.MAXIMIZE_BOX
[解决办法]
wx.MINIMIZE_BOX))
sizer = wx.BoxSizer(wx.VERTICAL)
self.list = TestVirtualList(self)
sizer.Add(self.list, 1, wx.EXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(True)
if __name__ == "__main__":
app = wx.PySimpleApp()
app.TopWindow = Test()
app.TopWindow.Show()
app.TopWindow.Center()
app.MainLoop()