尝试将字符串写入ListCtrl,我不完全理解其中的逻辑。这是正确的方式吗?
self.rightPanel = wx.ListCtrl(spliter, -1, style=wx.LC_REPORT)
self.rightPanel.InsertColumn(0, 'LineNumber')
self.rightPanel.InsertColumn(1, 'log')
self.rightPanel.SetColumnWidth(0, 8)
self.rightPanel.SetColumnWidth(1, 80)
def writeConsole(self,str):
item = wx.ListItem()
item.SetText(str)
item.SetTextColour(wx.RED)
item.SetBackgroundColour(wx.BLACK)
index = self.rightPanel.GetItemCount()
self.rightPanel.InsertItem(item)
self.rightPanel.SetStringItem(index, 0, str(index))
self.rightPanel.SetStringItem(index, 1, item.GetText())1-为什么文本不显示为彩色?
2-为什么在ListCtrl中有两种不同的文本显示方法?
ListCtrl.InsertItem()
ListCtrl.SetStringItem()我认为InsertItem只是将项目加载到list.SetString中,但显示了项目内容。(不确定)
发布于 2011-10-13 14:19:00
SetTextColour()和SetBackgroundColour()是整个listctrl的方法,而不是项的方法。对于应使用的项(仅对报告模式有效):
GetItemTextColour(idx_item)
SetItemTextColour(idx_item, col)InsertItem(index, item) (这里的item是wx.ListItem的一个实例)是在ListCtrl上添加新行的InsertItem()方法之一。
SetStringItem(index, col, label, imageId=-1) (其中索引和列参数是单元格的行和列索引)允许在任何选定的列中设置字符串。其他insert方法仅适用于第一列。
参考: wxPython in Action,Noel Rappin和Robin Dunn。
https://stackoverflow.com/questions/7748371
复制相似问题