I want to arrange some controls using BoxSizer in a SashLayoutWindow.
However, I found that if the number of controls in the BoxSizer is
more than one, all the controls disappear. It works okay if there is
only one control in the BoxSizer. What's wrong?
The following code is a simplified demo. It will show a frame with a
SashLayoutWindow on the left side, which contains a ListCtrl. But if
you uncomment the "box.Add" line (expect to add a StaticText uppon the
ListCtrl), both the StaticText and the ListCtrl disappear. Isn't it
confusious?
from wxPython.wx import *
class TestSashWindow(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self, parent, -1)
self.remainingSpace = wxPanel(self, -1, style=wxSUNKEN_BORDER)
EVT_SIZE(self, self.OnSize)
win = wxSashLayoutWindow(self, -1)
win.SetDefaultSize(wxSize(120, 100))
win.SetOrientation(wxLAYOUT_VERTICAL)
win.SetAlignment(wxLAYOUT_LEFT)
win.SetBackgroundColour(wxColour(0, 255, 0))
win.SetSashVisible(wxSASH_RIGHT, True)
win.SetExtraBorderSize(10)
box = wxBoxSizer(wxVERTICAL)
textWindow = wxListCtrl(win, -1)
#box.Add(wxStaticText(win, -1, 'aaa'), 1, wxEXPAND)
box.Add(textWindow, 1, wxEXPAND)
win.SetSizer(box)
win.Layout()
self.leftWindow1 = win
def OnSize(self, event):
wxLayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(None, -1, 'test')
self.SetTopWindow(frame)
TestSashWindow(frame)
frame.Show(True)
return True
app = MyApp(0)
app.MainLoop()