I am quiet new to wxPython, so I hope there is nothing basic I am overlooking: I want to use a SplitterWindow to split up my Frame's content in two resizable subwindows (A and B), but I want one of the windows (B) to have a MaxSize set.
Unfortunately, this poses a problem:
When I resize (enlarge), the whole frame (I am trying to adapt to the the wxPython terminology here; normally, I would say: resize the window), I would hope once the maxSize of the of Window B is reached, Window A would automatically be enlarged to fill the whole content of the frame. Sadly, it does not.
How do make sure that I am not able to move the sash to the left (decrease size of Window B)? In the current situation, Window B just moves to the left (does not change width) and exposes the blue background of the WindowSplitter.
Here's my code:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(500,300开发者_如何转开发))
# Create View
self.loadView()
#self.SetAutoLayout(1)
self.GetSizer().Fit(self)
self.Centre()
self.Show()
def loadView(self):
splitter = wx.SplitterWindow(self, wx.ID_ANY, style = wx.SP_BORDER, size=(500, 300))
splitter.SetBackgroundColour('#0000ff')
panelLeft = wx.Panel(splitter, size=(200,100))
panelLeft.SetBackgroundColour('#00ff00')
panelRight = wx.Panel(splitter, size=(200,100))
panelRight.SetBackgroundColour('#ff0000')
panelRight.SetMaxSize((200, -1))
splitter.SplitVertically(panelLeft, panelRight)
self.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.GetSizer().Add(splitter, 1, wx.EXPAND)
app = wx.App(False)
frame = MainWindow(None, "Test")
app.MainLoop()
A picture speaks a thousand words:
The blue area is part of the splitter, but not filled up by Window A.Any help/hint in the right direction is appreciated.
Thanks, Daniel
I no longer actively work with wx so cannot test a solution. However I believe what you are looking for is
SetSashGravity(0.5)
The default behaviour of a SplitterWindow is that upon a Resize event, only the Right or Bottom window will be resized. And in your case you have imposed a maximum size upon that window.
See the docs for SetSashGravity
精彩评论