Set colour to wx.listbox item

Question:

Wxpython provides the following api to change wx.listbox items colour:

wx.ListBox.SetItemBackgroundColour(self, item, c)

and

wx.ListBox.SetItemForegroundColour(self, item, c)

For some reason this functions fail to do so in my linux and windows.
Any one know why?

note that wx.ListBox.SetOwnBackgroundColor works perfectly.

Asked By: Jah

||

Answers:

My guess is that it is a limitation of the native widget. I’ve seen several widgets that you cannot set the background or foreground color of because that widget just doesn’t support it on that platform, but it DOES support it on other platform(s). You can ask over on the wxPython mailing list to make sure though. They have some of the primary wx devs there.

In the meantime, youmight look at VListBox or maybe switch to a ListCtrl.

Answered By: Mike Driscoll

You have to add wx.LB_OWNERDRAW style to your listbox

      self.list_box_1 = wx.ListBox(self.panel_1, wx.ID_ANY, choices=["test1","test2"] ,style=wx.LB_OWNERDRAW)
      self.list_box_1.SetItemForegroundColour(1,wx.Colour(219, 112, 219))
Answered By: yam ka