wxPython wxListCtrl选择了行颜色

flx*_*kid 4 wxpython row colors selected listctrl

我希望选择某些行的颜色为红色而不是标准颜色(窗口上的蓝色),以便我可以指示状态.任何人都知道wxPython中是否可以这样做?

Jim*_*oll 7

在您从wx.ListCtrl派生的类中,请查看覆盖

def OnGetItemAttr(self, item):
    return self.normalAttr[item % 2]
#
Run Code Online (Sandbox Code Playgroud)

使用以下方法提前初始化项属性的位置:

    self.normalAttr = []
    self.normalAttr.append(wx.ListItemAttr())
    grayAttr = wx.ListItemAttr()
    grayAttr.SetBackgroundColour(lightGray)
    self.normalAttr.append(grayAttr)
Run Code Online (Sandbox Code Playgroud)

所以在这种情况下,我在默认和浅灰色属性之间交替使用背景颜色.

为绘制的每一行调用此函数,因此您可以使用它来指示各种状态.如果选择行应该是一个简单的案例.