Search code examples
pythonuser-interfacewxpythonwxwidgets

Something like the wx.MultiChoiceDialog in a panel instead of a dialog


I'd like to use the list (with checkboxes next to each item) that is contained in the wxMultiChoice dialog in a panel. Is that possible?


Solution

  • The equivalent to a wx.MultiChoiceDialog is the wx.CheckListBox

    import wx
    
    class MyFrame(wx.Frame):
        def __init__(self, parent):
            wx.Frame.__init__(self, parent, -1)
    
            sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                          'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
                          'more', 'and more']
    
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            self.clb = wx.CheckListBox(self, -1, (30,30), wx.DefaultSize, sampleList)
            self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.clb)
            self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, self.clb)
            self.clb.SetSelection(0)
    
            sizer.Add(wx.Panel(self), 1, flag=wx.EXPAND)
            sizer.Add(self.clb, 0, flag=wx.EXPAND)
            sizer.Add(wx.Panel(self), 1, flag=wx.EXPAND)
            self.SetSizer(sizer)
            self.Fit()
    
    
        def EvtListBox(self, event):
            pass
    
        def EvtCheckListBox(self, event):
            pass
    
    
    if __name__ == '__main__':
    
        app = wx.PySimpleApp()
        frame = MyFrame(None)
        frame.Show(True)
        app.MainLoop()