Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import wx
- import math
- class Example(wx.Dialog):
- def __init__(self, cb_titles, title):
- super().__init__(None, title=title)
- self.cb_labels = cb_titles
- self.panel = wx.Panel(self)
- self.initUI()
- self.Centre()
- self.ShowModal()
- def initUI(self):
- vbox = wx.BoxSizer(wx.VERTICAL) # I use vbox here because I need to add other items below this grid sizer, not shown in the example.
- self.set_grid(vbox)
- border = wx.BoxSizer()
- border.Add(vbox, 1, wx.ALL | wx.EXPAND, 10)
- self.panel.SetSizer(border)
- self.panel.Fit()
- def set_grid(self, vbox):
- n_cbs = len(self.cb_labels)
- n_col = int(math.sqrt(n_cbs))
- n_row = n_col
- while n_row * n_col < n_cbs:
- n_row += 1
- sb = wx.StaticBox(self.panel, -1, 'CheckBoxes:')
- sb_sizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
- grid_sizer = wx.GridSizer(n_row, n_col, 30)
- for i in range(n_cbs):
- cb_label = self.cb_labels[i]
- cb = wx.CheckBox(self.panel, label=cb_label)
- grid_sizer.Add(cb, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
- sb_sizer.Add(grid_sizer, 1, wx.ALL|wx.CENTER, 10)
- vbox.Add(sb_sizer, 1, wx.CENTER, 0)
- app = wx.App()
- cb_titles = ["aaaaaaaaaaa", "bbbbbbb", "cccccccccc", "ddddddd", "eeeeeeee", "ffffffffff", "DDDDDDDDDD", 'FFFFFFFFFFFFFF', "GGGGGGGGGG"] * 3 # you can change this number
- Example(cb_titles, title ='Question Example')
- app.MainLoop()
Add Comment
Please, Sign In to add comment