Use arbitrary wx objects as a column in wx.ListCtrl

I have wx.ListCtrl that has the wx.ListCtrl bit wx.LC_REPORT . It has 3 columns. I want the first column to be populated with a check box for every other record. I tried using the ListCtrl.InsertItem method, but it takes only one argument ( info ), and I cannot find any documents as to what this argument should do. I tried just passing wx.CheckBox to InsertItem no avail.

Is it possible to set a checkbox as an entry in wxPython ListCtrl? If so, how would I do it?

If there is any ambiguity about what I'm talking about, here is a picture of what I want (not sure if this is wx, but this is what I'm looking for). I want the checkboxes next to 1..5 in column No.

list control with checkboxes

+6
python wxpython listctrl
source share
1 answer

Take a look at wx.lib.mixins.listctrl .

 import wx import wx.lib.mixins.listctrl as listmix class TestListCtrl(wx.ListCtrl, listmix.CheckListCtrlMixin, listmix.ListCtrlAutoWidthMixin): def __init__(self, *args, **kwargs): wx.ListCtrl.__init__(self, *args, **kwargs) listmix.CheckListCtrlMixin.__init__(self) listmix.ListCtrlAutoWidthMixin.__init__(self) self.setResizeColumn(3) def OnCheckItem(self, index, flag): print(index, flag) class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.panel = wx.Panel(self) self.list = TestListCtrl(self.panel, style=wx.LC_REPORT) self.list.InsertColumn(0, "No.") self.list.InsertColumn(1, "Progress") self.list.InsertColumn(2, "Description") self.list.Arrange() for i in range(1, 6): self.list.Append([str(i), "", "It the %d item" % (i)]) self.button = wx.Button(self.panel, label="Test") self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.list, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) self.sizer.Add(self.button, flag=wx.EXPAND | wx.ALL, border=5) self.panel.SetSizerAndFit(self.sizer) self.Show() app = wx.App(False) win = MainWindow(None) app.MainLoop() 
+8
source share

All Articles