Vlákno názorů k článku Programovací jazyk TCL od stefan - testovane v konfiguracii: python-2.4.1, wxPython-2.5.3 import wx class ChecksDialog(wx.Dialog): ...

  • Článek je starý, nové názory již nelze přidávat.
  • 24. 7. 2005 14:19

    stefan (neregistrovaný)
    testovane v konfiguracii: python-2.4.1, wxPython-2.5.3

    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()
    
    
  • 24. 7. 2005 21:42

    slacker (neregistrovaný)
    Dovolil bych si provést menši opravu. Jinak se aplikace při zavření okna neukonči korektně.
    #!/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()