wxPython ListCtrl:编写带颜色的文本

3
尝试将字符串写入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中,但显示项目内容。(不确定)
1个回答

6

SetTextColour()SetBackgroundColour()是整个列表控件的方法,而不是项目的方法。 对于项目,您应该使用(仅适用于报告模式):

GetItemTextColour(idx_item)
SetItemTextColour(idx_item, col)

InsertItem(index, item) (其中item是wx.ListItem的一个实例) 是在ListCtrl上添加新行的InsertItem()方法之一。

SetStringItem(index, col, label, imageId=-1)(其中索引和列参数是单元格的行和列索引)允许在任何选定的列中设置字符串。其他插入方法仅适用于第一列。

参考资料:wxPython in Action,Noel Rappin和Robin Dunn。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接