![]() |
Why is wx.NO_BORDER changing panels within a frame - 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: Why is wx.NO_BORDER changing panels within a frame (/thread-28271.html) |
Why is wx.NO_BORDER changing panels within a frame - MeghansUncle2 - Jul-12-2020 In the code below (within wx.Frame.__init__) when I add "style=wx.NO_BORDER" the panels shrink to almost nothing. Please run with and without this style to see the difference. Can anyone explain this behavior? I am learning Python and this behavior seems to me to be in error. I would like to understand why this is happening so that I can prevent it. import wx ######################################################################## class RandomPanel(wx.Panel): """""" #---------------------------------------------------------------------- def __init__(self, parent, color): """Constructor""" wx.Panel.__init__(self, parent) self.SetBackgroundColour(color) ######################################################################## class MainPanel(wx.Panel): """""" #---------------------------------------------------------------------- def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent) topSplitter = wx.SplitterWindow(self) hSplitter = wx.SplitterWindow(topSplitter) panelOne = RandomPanel(hSplitter, "blue") panelTwo = RandomPanel(hSplitter, "red") hSplitter.SplitVertically(panelOne, panelTwo) hSplitter.SetSashGravity(0.7) panelThree = RandomPanel(topSplitter, "green") topSplitter.SplitHorizontally(hSplitter, panelThree) topSplitter.SetSashGravity(0.5) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(topSplitter, 1, wx.EXPAND) self.SetSizer(sizer) ######################################################################## class MainFrame(wx.Frame): """""" #---------------------------------------------------------------------- def __init__(self): """Constructor""" wx.Frame.__init__(self, None, title="", size=(800,600), style=wx.NO_BORDER) panel = MainPanel(self) self.Show() #---------------------------------------------------------------------- if __name__ == "__main__": app = wx.App(False) frame = MainFrame() app.MainLoop() RE: Why is wx.NO_BORDER changing panels within a frame - Larz60+ - Jul-12-2020 Works fine when I try it. RE: Why is wx.NO_BORDER changing panels within a frame - Yoriz - Jul-12-2020 Calling layout fixes it import wx ######################################################################## class RandomPanel(wx.Panel): """""" #---------------------------------------------------------------------- def __init__(self, parent, color): """Constructor""" wx.Panel.__init__(self, parent) self.SetBackgroundColour(color) ######################################################################## class MainPanel(wx.Panel): """""" #---------------------------------------------------------------------- def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent) topSplitter = wx.SplitterWindow(self) hSplitter = wx.SplitterWindow(topSplitter) panelOne = RandomPanel(hSplitter, "blue") panelTwo = RandomPanel(hSplitter, "red") hSplitter.SplitVertically(panelOne, panelTwo) hSplitter.SetSashGravity(0.7) panelThree = RandomPanel(topSplitter, "green") topSplitter.SplitHorizontally(hSplitter, panelThree) topSplitter.SetSashGravity(0.5) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(topSplitter, 1, wx.EXPAND) self.SetSizer(sizer) ######################################################################## class MainFrame(wx.Frame): """""" #---------------------------------------------------------------------- def __init__(self): """Constructor""" wx.Frame.__init__(self, None, title="", size=(800,600), style=wx.BORDER_NONE) panel = MainPanel(self) self.Layout() self.Show() #---------------------------------------------------------------------- if __name__ == "__main__": app = wx.App(False) frame = MainFrame() app.MainLoop()Note: https://wxpython.org/Phoenix/docs/html/wx.Window.html#styles-window-styles Wrote:Window Styles RE: Why is wx.NO_BORDER changing panels within a frame - MeghansUncle2 - Jul-12-2020 THANK YOU Yoriz!!! Can you briefly explain WHY this works? RE: Why is wx.NO_BORDER changing panels within a frame - Yoriz - Jul-12-2020 https://docs.wxpython.org/wx.Window.html#wx.Window.Layout Wrote:Layout(self) |