Python Forum
Why is wx.NO_BORDER changing panels within a frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is wx.NO_BORDER changing panels within a frame
#1
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()
Reply
#2
Works fine when I try it.
Reply
#3
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/w...dow-styles Wrote:Window Styles
  • wx.BORDER_NONE: Displays no border, overriding the default border style for the window. wx.NO_BORDER is the old name for this style.
Reply
#4
THANK YOU Yoriz!!!

Can you briefly explain WHY this works?
Reply
#5
https://docs.wxpython.org/wx.Window.html...dow.Layout Wrote:Layout(self)
Lays out the children of this window using the associated sizer.

If a sizer hadn’t been associated with this window (see SetSizer ), this function doesn’t do anything, unless this is a top level window (see wx.TopLevelWindow.Layout ).

Note that this method is called automatically when the window size changes if it has the associated sizer (or if SetAutoLayout with True argument had been explicitly called), ensuring that it is always laid out correctly.

Return type
bool

Returns
Always returns True, the return value is not useful.

See also Window Sizing Overview
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,012 Sep-30-2021, 05:57 PM
Last Post: menator01
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,651 Jul-29-2020, 07:13 PM
Last Post: deanhystad
  [Tkinter] changing the frame colour nick123 4 16,427 Jul-24-2020, 07:32 AM
Last Post: LegacyCoding
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 8,944 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,000 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,368 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020