Ultimatelistctrl Checkbox grid

This code creates a grid of checkboxes representing every hour of a week:

import wx
import wx.lib.agw.ultimatelistctrl as ULC

class GridBox(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, -1, title = 'Checkbox Grid', style=wx.DEFAULT_DIALOG_STYLE, size=(654,220))
        self.mylist = ULC.UltimateListCtrl(self, -1, agwStyle=agwStyle, size=(640,180))
        #self.Bind(ULC.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.mylist)
        self.mylist.InsertColumn(0,"", width=80)

        for col in range(1,25):
            if col==0:col_num=""
            self.mylist.InsertColumn(col,col_num, width=22)

        self.checkboxes = {}
        d = 0

        while True:
            self.mylist.InsertStringItem(d, str(days[d]))
            d += 1
            if d == 7: break

        for boxes in range(1,25):
            b = 0
            while True:
                day = days[b]
                hour = boxes-1
                name_of_checkbox = "{day}_{hour}".format(day=day, hour=hour)
                self.mylist.SetStringItem(b, boxes, "")
                self.checkBox = wx.CheckBox(self.mylist, -1, "", wx.DefaultPosition, wx.DefaultSize, 0, name = name_of_checkbox)
                self.checkBox.SetValue(True) #Use this to check all boxes
                self.checkboxes[self.checkBox.GetId()] = b
                self.mylist.SetItemWindow(b, boxes, self.checkBox)
                b += 1
                if b == 7: break
class MyApp(wx.App):
    def OnInit(self):
        dlg = GridBox(None)
        return True
if __name__ == "__main__":
    myapp = MyApp(redirect=False)

It works fine under windows 10 with Python 3.6.3/wx 4.0.1 but after upgrading to Python 3.10/wx 4.2.0 only the first row gets populated with checkboxes…

FWIW under Windows 11, Python 3.10.8 and wxPython 4.2.0 I just get a completely blank frame (after correcting for invalid double quote characters and bad incorrect indentation).

The indentation is correct in the draft but not in the post.
There are no invalid double quotes.

The double quotes in “Checkbox Grid” are invalid.

If, instead of putting your code in a quote block, you put three grave characters (`) before the first line of code and three grave characters after the last line of code, the forum software will leave it formatted as you intended and we will be able to copy and paste it much more easily. This is effectively what what the “Preformatted text” button (</>) on the post editing toolbar does.

Unfortunately, we don’t have access to the draft, just the post.

Thanks. Corrected.

Try adding expand=True to the SetItemWindow() call - it works on linux, but I can’t test on windows.

 self.mylist.SetItemWindow(b, boxes, self.checkBox, expand=True)

Also, you could make the code that populates the list control a little more concise, like this:

        days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

        for d, day in enumerate(days):
            self.mylist.InsertStringItem(d, day)

            for col in range(1, 25):
                hour = col - 1
                name_of_checkbox = "{day}_{hour}".format(day=day, hour=hour)
                self.mylist.SetStringItem(d, col, "")
                checkBox = wx.CheckBox(self.mylist, -1, "", wx.DefaultPosition, wx.DefaultSize, 0,
                checkBox.SetValue(True)  # Use this to check all boxes
                self.checkboxes[checkBox.GetId()] = d
                self.mylist.SetItemWindow(d, col, checkBox, expand=True)

Working perfectly, and much neater. Thank you.