[WxPython] Why is choicebox not displayed? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [WxPython] Why is choicebox not displayed? (/thread-1691.html) |
Why is choicebox not displayed? - merlem - Jan-20-2017 The code: import wx showliste = ["item1", "item2", "item3"] class Mainframe(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) self.shopanel = Shopanel(self, id) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.shopanel, 0, wx.EXPAND) self.SetSizer(vbox) self.Show() class Shopanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) self.SetMinSize((100, 100)) self.SetMaxSize((150, 150)) chos = wx.MultiChoiceDialog(self, "show:", "", showliste) chos.SetSelections(range(len(showliste[:-1]))) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add(chos) self.SetSizerAndFit(hbox) if __name__ == "__main__": app = wx.App(0) Mainframe(None, -1, "Mainframe") app.MainLoop()And two questions: First and more important, why is the choicebox not shown? I simply get an empty window. Second, how to make SetMinSize and SetMaxSize doing something, in the best case even influencing the panelsize? Actually, they just seem to do... nothing. RE: Why is choicebox not displayed? - Yoriz - Jan-20-2017 A wx.MultiChoiceDialog is a type of ready built frame with widgets already contained, it is not supposed to be used as a child widget of another frame, it is shown using ShowModal, maybe a a wx.ListCtrl with a checklist mixin is the control you are after. SetMinSize & SetMaxSize is probably better setting for the parent frame. import wx from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin showliste = ["item1", "item2", "item3"] class Mainframe(wx.Frame): def __init__(self, parent, id_, title): wx.Frame.__init__(self, parent, id_, title) self.SetMinSize((100, 100)) self.SetMaxSize((150, 150)) self.shopanel = Shopanel(self, id_) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.shopanel, 1, wx.EXPAND) self.SetSizer(vbox) self.Fit() self.Show() class TestListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin): def __init__(self, *args, **kwargs): wx.ListCtrl.__init__(self, *args, **kwargs) CheckListCtrlMixin.__init__(self) ListCtrlAutoWidthMixin.__init__(self) class Shopanel(wx.Panel): def __init__(self, parent, id_): wx.Panel.__init__(self, parent, id_) chos = TestListCtrl(self, style=wx.LC_REPORT) chos.InsertColumn(0, '') chos.InsertColumn(1, 'Item') chos.SetColumnWidth(0, 30) for item in showliste: chos.Append(('', item)) chos.CheckItem(0) chos.CheckItem(1) chos.Select(0) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add(chos, 1, wx.EXPAND| wx.ALL, 5) self.SetSizer(hbox) if __name__ == "__main__": app = wx.App(0) Mainframe(None, -1, "Mainframe") chos = wx.MultiChoiceDialog(None, "show:", "", showliste) chos.SetSelections(range(len(showliste[:-1]))) chos.ShowModal() app.MainLoop() RE: Why is choicebox not displayed? - merlem - Jan-21-2017 Thank you very much for your help! It's even less complicated, I was looking for wx.ListCtrl and just didn't find the right thing. And same is true for the size... I wish to define the size for the single panel, but I probably should try to set it in the superordinate vbox. The wx.lib.mixins.listctrl looks also very interesting, but there is probably no detailed documentation or explanation somewhere in the web? I found some words about it in the API docs, but it's confusing for someone who still needs an explication, not only a list of possibilities. |