import wx
class MyDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title="Get widget value", pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
v_box = wx.BoxSizer(wx.VERTICAL)
self.panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.Size(200, 300), wx.TAB_TRAVERSAL)
self.sizer_of_button_validator_and_chek_boxes = wx.BoxSizer(wx.VERTICAL)
self.button_validator = wx.Button(self.panel, wx.ID_ANY, u"call_validation", wx.DefaultPosition, wx.DefaultSize,
0)
self.button_validator.Bind(wx.EVT_BUTTON, self.call_validation)
self.sizer_of_button_validator_and_chek_boxes.Add(self.button_validator, 0, wx.ALL, 5)
lista = range(0, 5)
for number in lista:
name = 'check_box_' + str(number)
self.check_box = wx.CheckBox(self.panel, wx.ID_ANY, u"Check Me!", wx.DefaultPosition, wx.DefaultSize,
name=name)
self.sizer_of_button_validator_and_chek_boxes.Add(self.check_box, 0, wx.ALL, 5)
print(self.check_box.GetName())
self.panel.SetSizer(self.sizer_of_button_validator_and_chek_boxes)
self.panel.Layout()
self.sizer_of_button_validator_and_chek_boxes.Fit(self.panel)
v_box.Add(self.panel, 1, wx.EXPAND | wx.ALL, 5)
self.SetSizer(v_box)
self.Layout()
v_box.Fit(self)
self.Centre(wx.BOTH)
def call_validation(self,event):
children = self.sizer_of_button_validator_and_chek_boxes.GetChildren()
for child in children:
widget = child.GetWindow()
if isinstance(widget, wx.CheckBox):
print(widget.GetName(),widget.GetValue())
if __name__ == "__main__":
app = wx.App()
frame = MyDialog(None)
frame.Show()
app.MainLoop()