This is so frustrating, because I have done this before, but for some reason I can not figure out what is going on. I’ve been messing with this for 3 hours I have distilled a runnable code snippet that shows the problem. I am trying to resize windows in a wx.FlexGridSizer
, but every time I call Layout()
it forces the windows back to their original size. I want the sizer to reposition the windows with their new size, but it’s not working:
import wx
import wx.lib.scrolledpanel as scrolled
app = wx.App()
root = wx.Frame(None)
root.Maximize(True)
vbox = wx.BoxSizer()
root.SetSizer(vbox)
################################################################
scrolly = scrolled.ScrolledPanel(root, size=root.GetSize())
fgs = wx.FlexGridSizer(cols=1, vgap=10, hgap=10)
scrolly.SetSizer(fgs)
scrolly.SetupScrolling()
scrolly.SetBackgroundColour(wx.WHITE)
vbox.Add(scrolly)
window = wx.Window(scrolly, size=(1000,1000))
window.SetBackgroundColour(wx.BLUE)
page = wx.Window(scrolly, size=(1000,1000))
page.SetBackgroundColour(wx.BLACK)
fgs.Add(window)
fgs.Add(page)
def zoom(_):
page.SetSize(500,500)
window.SetSize(600,600)
fgs.Layout()
root.Bind(wx.EVT_CHAR_HOOK, lambda e: zoom(e))
#################################################################
def on_resize(e):
scrolly.SetSize(root.GetVirtualSize())
scrolly.Update()
scrolly.SetupScrolling(scrollToTop=False)
root.Bind(wx.EVT_SIZE, on_resize)
root.Show()
app.MainLoop()