import wx
class ChecksDialog(wx.Dialog):
ID_BUTTON_PRINT = 5001
def __init__(self, parent, ID, title):
wx.Dialog.__init__(self, parent, ID, title)
sizer = wx.BoxSizer(wx.VERTICAL)
labels = ['first', 'second', 'third', 'fourth', 'fifth']
self.checks = [wx.CheckBox(self, -1, label) for label in labels]
for check in self.checks:
sizer.Add(check, 0, wx.ALL, 5)
button = wx.Button(self, self.ID_BUTTON_PRINT, 'Print')
sizer.Add(button, 0, wx.ALL|wx.ALIGN_CENTER, 5)
wx.EVT_BUTTON(self, self.ID_BUTTON_PRINT, self.OnButton)
self.SetSizerAndFit(sizer)
def OnButton(self, event):
for check in self.checks:
if check.IsChecked():
print check.GetLabel(), ' checked'
else:
print check.GetLabel(), ' not checked'
class ChecksApp(wx.App):
def OnInit(self):
dlg = ChecksDialog(None, -1, "Checkboxes Demo")
dlg.Show(True)
self.SetTopWindow(dlg)
return True
app = ChecksApp(0)
app.MainLoop()
#!/usr/bin/python
# -*- coding: iso8859-2
import wx
class ChecksDialog(wx.Dialog):
ID_BUTTON_PRINT = 5001
def __init__(self, parent, ID, title):
wx.Dialog.__init__(self, parent, ID, title)
sizer = wx.BoxSizer(wx.VERTICAL)
labels = ['first', 'second', 'third', 'fourth', 'fifth']
self.checks = [wx.CheckBox(self, -1, label) for label in labels]
for check in self.checks:
sizer.Add(check, 0, wx.ALL, 5)
button = wx.Button(self, self.ID_BUTTON_PRINT, 'Print')
sizer.Add(button, 0, wx.ALL|wx.ALIGN_CENTER, 5)
wx.EVT_BUTTON(self, self.ID_BUTTON_PRINT, self.OnButton)
wx.EVT_CLOSE(self, self.OnQuit)
self.SetSizerAndFit(sizer)
def OnButton(self, event):
for check in self.checks:
if check.IsChecked():
print check.GetLabel(), ' checked'
else:
print check.GetLabel(), ' not checked'
def OnQuit(self, event):
self.Destroy()
class ChecksApp(wx.App):
def OnInit(self):
dlg = ChecksDialog(None, -1, "Checkboxes Demo")
dlg.Show(True)
self.SetTopWindow(dlg)
return True
app = ChecksApp(0)
app.MainLoop()