Having a sizer problem; why does my wxPython window layout look fine when resizing larger, but break when resizing smaller?

I’m trying to lay out a window with a 3:1 height ratio for a wx.grid.Grid (3) and a wx.Button (1). This sounds like a job for a BoxSizer! So I wrote this:

frame = wx.Frame(None, title="Hello World")
sizer = wx.BoxSizer(wx.VERTICAL)
grid = sudoku_9x9grid(frame)
sizer.Add(grid, 3, wx.EXPAND, 8)
button = wx.Button(frame, label="GO BUTTON")
sizer.Add(button, 1, wx.SHAPED | wx.ALIGN_CENTER)

# Show it.

# Start the event loop.

It works as intended when I’m dragging the window large, but when I drag the window smaller, the sizer doesn’t maintain the height ratio I intended:

I’m sure I’m doing something wrong setting flags to the Sizer, but I haven’t figured out what. Any suggestions?


I think you need to change:

- sizer.Add(grid, 3, wx.EXPAND, 8)
+ sizer.Add(grid, 3, wx.SHAPED, 8)

see also: Sizers Overview — wxPython Phoenix 4.1.2a1 documentation

The item will be expanded as much as possible while also maintaining its aspect ratio