Set sash gravity of a vertically splitted window

I’ve nested splited windows in this way and I am able to change the sash gravity “propotional position” of the horizontal splits but not of the vertical one, any idea?


class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "ScrolledThumb Demo", size=(1600,800))
       
        splitter = wx.SplitterWindow(self)
        splitter2 = wx.SplitterWindow(splitter)

        vsplitter = wx.SplitterWindow(splitter)

        thumbnail_angles = ThumbnailAngles(vsplitter)

        preview_panel = ImagePreview(vsplitter)
        thumbnail_panel = ThumbnailsPanel(splitter2)
        action_panel = ActionPanel(splitter2)
        
        vsplitter.SetSplitMode(wx.SPLIT_VERTICAL)
        vsplitter.SplitVertically(thumbnail_angles, preview_panel)
        vsplitter.SetSashGravity(0.2)

        splitter2.SplitHorizontally(thumbnail_panel, action_panel)
        splitter2.SetSashGravity(0.5)

        splitter.SplitHorizontally(vsplitter, splitter2)
        splitter.SetSashGravity(0.5)
       
        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        newitem = wx.MenuItem(fileMenu,wx.ID_NEW, text="New", kind=wx.ITEM_NORMAL)
        fileMenu.Append(newitem)
        fileMenu.AppendSeparator()
        quit = wx.MenuItem(fileMenu, wx.ID_EXIT, '&Quit\tCtrl+Q')
        fileMenu.Append(quit)
    
        open_files = wx.MenuItem(fileMenu, wx.ID_OPEN , text="Add Images", kind=wx.ITEM_NORMAL )
        fileMenu.Append(open_files)

        fileMenu.Bind(event=wx.EVT_MENU, handler=self.myFunc, source=open_files)

        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)

        self.Centre()
        wx.CallLater(100, self.Maximize, True)

I have modified your example so that I can run it and try to see how the splitter windows are behaving.

I have created fake classes to represent the ones that are contained by the splitter windows. The fake classes have unique colours and labels so I can more easily see where they are located and how they are changing.

import wx

class ThumbnailAngles(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent)
        self.SetBackgroundColour(wx.Colour(35, 142, 35))
        label = wx.StaticText(self, label="ThumbnailAngles", pos=(20,20))
        label.SetBackgroundColour(wx.WHITE)

class ImagePreview(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent)
        self.SetBackgroundColour(wx.Colour(0, 127, 255))
        label = wx.StaticText(self, label="ImagePreview", pos=(20,20))
        label.SetBackgroundColour(wx.WHITE)

class ThumbnailsPanel(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent)
        self.SetBackgroundColour(wx.Colour(204, 50, 50))
        label = wx.StaticText(self, label="ThumbnailsPanel", pos=(20,20))
        label.SetBackgroundColour(wx.WHITE)

class ActionPanel(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent)
        self.SetBackgroundColour(wx.Colour(255, 255, 0))
        label = wx.StaticText(self, label="ActionPanel", pos=(20,20))
        label.SetBackgroundColour(wx.WHITE)

class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "ScrolledThumb Demo", size=(1600, 800))

        splitter = wx.SplitterWindow(self)
        splitter2 = wx.SplitterWindow(splitter)

        vsplitter = wx.SplitterWindow(splitter)

        thumbnail_angles = ThumbnailAngles(vsplitter)

        preview_panel = ImagePreview(vsplitter)
        thumbnail_panel = ThumbnailsPanel(splitter2)
        action_panel = ActionPanel(splitter2)

        vsplitter.SetSplitMode(wx.SPLIT_VERTICAL)
        vsplitter.SplitVertically(thumbnail_angles, preview_panel)
        vsplitter.SetSashGravity(0.2)

        splitter2.SplitHorizontally(thumbnail_panel, action_panel)
        splitter2.SetSashGravity(0.5)

        splitter.SplitHorizontally(vsplitter, splitter2)
        splitter.SetSashGravity(0.5)

        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        newitem = wx.MenuItem(fileMenu, wx.ID_NEW, text="New", kind=wx.ITEM_NORMAL)
        fileMenu.Append(newitem)
        fileMenu.AppendSeparator()
        quit = wx.MenuItem(fileMenu, wx.ID_EXIT, '&Quit\tCtrl+Q')
        fileMenu.Append(quit)

        open_files = wx.MenuItem(fileMenu, wx.ID_OPEN, text="Add Images", kind=wx.ITEM_NORMAL)
        fileMenu.Append(open_files)

        fileMenu.Bind(event=wx.EVT_MENU, handler=self.myFunc, source=open_files)

        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)

        self.Centre()
        wx.CallLater(100, self.Maximize, True)

    def myFunc(self, _evt):
        pass


if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()

Here is a screen dump of the frame after it has been unmaximised:

When the frame is maximised, moving the horizontal sashes cannot resize the width of the top splitter window, so the gravity does not come into play.

However, when the frame is unmaximised and the width of the frame itself is changed, then the gravity does seem to me to be allowing the ImagePreview panel to change much faster than the ThumbnailAngles panel?

vokoscreenNG-2025-05-02_19-21-12

I junda managed to make it work and favor one side more than the over using the init sash line (225) variable when creating the scrolled windows so it became minor though it’s still anoyying how basic functionalities like this in wxpython doesn’t work as smooth on ubuntu…