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))
agwStyle = (ULC.ULC_HAS_VARIABLE_ROW_HEIGHT | wx.LC_REPORT | wx.LC_VRULES | wx.LC_HRULES | wx.LC_SINGLE_SEL)
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):
col_num=str(col-1)
if col==0:col_num=""
self.mylist.InsertColumn(col,col_num, width=22)
self.checkboxes = {}
self.boxes=[]
d = 0
while True:
days=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
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)
self.boxes.append(self.checkBox)
b += 1
if b == 7: break
#----------------------------------------------------------------------
class MyApp(wx.App):
def OnInit(self):
dlg = GridBox(None)
dlg.ShowModal()
dlg.Destroy()
return True
if __name__ == "__main__":
myapp = MyApp(redirect=False)
myapp.MainLoop()
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…