python:在列表视图中设置单行颜色
我正在进行一些测试,并创建了一个列表,用来在图形界面上显示这些测试的结果。
self.listCtrl1 = wx.ListCtrl(id=wxID_FRAME1LISTCTRL1, name='listCtrl1',
parent=self.panel1, pos=wx.Point(15, 24), size=wx.Size(808, 419),
style=wx.LC_REPORT)
self._init_coll_listCtrl1_Columns(self.listCtrl1)
self.listCtrl1.Append([datetime.datetime.now(),action,result])
我想做的是,根据测试是通过还是失败,来改变列表中每个项目的颜色。请问这怎么实现呢(如果可以的话)
2 个回答
0
这段代码应该可以改变一个项目的背景颜色:
idx = self.listCtrl.InsertStringItem(sys.maxint, datetime.datetime.now())
self.listCtrl.SetStringItem(idx, 1, action)
self.listCtrl.SetStringItem(idx, 2, result)
self.listrCtrl.SetItemBackgroundColour(self, item=idx, col='#0000FF')
你需要知道它的索引,但wx.ListCtrl.Append这个方法不会返回这个索引。
0
可以通过使用 SetItemBackgroundColor 来实现这个功能。想了解更多细节,可以查看这个API文档:http://www.wxpython.org/docs/api/wx.ListCtrl-class.html