UltimateListCtrl 设置方法不起作用

UltimateListCtrl set method not working

我正在使用 wxPython,我正在尝试设置 UltimateListCtrl 中特定项目的背景颜色。当我为特定项目设置文本时,如下所示:

list.SetItemText(1,"something")

这没有任何问题。但是,当我尝试使用 SetItemBackgroundColour 时,例如,像这样:

list.SetItemBackgroundColour(1,'#0000FF')

我收到一个不知道如何修复的奇怪错误:

Traceback (most recent call last):
  File "C:\Program Files\DeVIDE-RE\python\lib\site-packages\wx-2.8-msw-unicode\w
x\lib\agw\ultimatelistctrl.py", line 6891, in OnPaint
    enabled = theLine.GetItem(0, CreateListItem(line, 0)).IsEnabled()
  File "C:\Program Files\DeVIDE-RE\python\lib\site-packages\wx-2.8-msw-unicode\w
x\lib\agw\ultimatelistctrl.py", line 4000, in GetItem
    return item.GetItem(info)
  File "C:\Program Files\DeVIDE-RE\python\lib\site-packages\wx-2.8-msw-unicode\w
x\lib\agw\ultimatelistctrl.py", line 3079, in GetItem
    if self._attr.HasTextColour():
  File "C:\Program Files\DeVIDE-RE\python\lib\site-packages\wx-2.8-msw-unicode\w
x\lib\agw\ultimatelistctrl.py", line 1183, in HasTextColour
    return self._colText.Ok()
AttributeError: 'str' object has no attribute 'Ok'

这真的很奇怪,因为 SetItemText 工作正常。我检查了 documentation 但我不明白为什么它不起作用。

有什么建议吗?

您需要传递有效的 Color object in SetItemBackgroundColour 而不是颜色字符串。

blue = Color(0, 0, 255)
list.SetItemBackgroundColour(1, blue)