Using wxPython 4.1.1 on Windows 10 with Python 3.9.4
I’ve created a simple ListCtrl in REPORT mode, and I’m trying to set the header attributes (to use bold font) with the “SetHeaderAttr” method as listed in the wxPython 4.1.1 API documentation for wx.ListCtrl. Here’s the code:
# Testing ListCtrl
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent)
# Define some rows of data
row1 = [355, 'Client', 'Zingall']
row2 = [1, 'ShipTo', 'Smith']
row3 = [55536, 'B2B', 'Summer Supplies']
# create a listctrl
self.list = wx.ListCtrl(self, -1,
style = wx.LC_REPORT
| wx.LC_HRULES
| wx.LC_VRULES
| wx.LC_SINGLE_SEL)
self.list.AppendColumn('ID')
self.list.AppendColumn('Type')
self.list.AppendColumn('LastName')
# attribute = (textcolor, backgroundcolor, font)
listfont = self.list.GetFont()
headfont = listfont.MakeBold()
headAttr = ((0,0,0), (240,240,240), headfont)
self.list.SetHeaderAttr(headAttr)
self.list.Append(row1)
self.list.Append(row2)
self.list.Append(row3)
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add(self.list, 1, wx.EXPAND)
self.SetSizer(layout)
self.Layout()
class MyFrame(wx.Frame):
def __init__(self, parent, title=""):
super().__init__(parent, title=title)
self.SetSize((640, 480))
# Set the panel
self.panel = MyPanel(self)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title='ListCtrl Testing')
self.frame.Show();
return True
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
I believe this should work, but it fails with:
AttributeError: 'ListCtrl' object has no attribute 'SetHeaderAttr'
The API says this method is new in 4.1, but it doesn’t seem to be there. Am I missing something or is the method missing? Any ideas?
Thanks