So, I've got this code mess that I think it can get a little bit tidier.
You might find a wx.GridBagSizer useful for this. The standard demo set has a nice example that shows how you can have widgets span multiple cells, make some cells growable, etc.
wxWize (GitHub - AndersMunch/wxWize: wxPython object builder library) can help cut down on the sizer boilerplate. Whether you use BoxSizer's or GridBagSizer.
You'd still need the same number of sizers, but it does away with the explicit .Add's, and the structure of the code comes to better match the structure of the sizer hierarchy, making the code easier to follow and refactor.
Here's a first approximation to Boštjan's design, as a complete runnable program:
import wx
import wize as iz
class MyFrame(wx.Frame):
def __init__(self):
with iz.Frame(init=self, title="Demo") as the_frame:
with iz.BoxSizer(wx.VERTICAL, proportion=1):
iz.StretchSpacer()
with iz.BoxSizer(wx.HORIZONTAL, proportion=1):
iz.StretchSpacer()
iz.StaticText(u"element1")
iz.StaticText(u"element2")
iz.StretchSpacer()
with iz.BoxSizer(wx.HORIZONTAL, proportion=1):
iz.StretchSpacer()
iz.StaticText(u"element3")
iz.StaticText(u"element4")
iz.StretchSpacer()
with iz.BoxSizer(wx.HORIZONTAL, proportion=1):
iz.StretchSpacer()
iz.StaticText(u"element5")
iz.StretchSpacer()
iz.StretchSpacer()
app = wx.App()
MyFrame().Show(True)
app.MainLoop()
I second the recommendation of GridBagSizer though. All those BoxSizers and StretchSpacer's can become a little fiddly.
Disclaimer: In case it isn't obvious, I am the author of wxWize.
regards, Anders
···
Matt Newville, matt.newville@gmail.com, wrote:
Boštjan Mejak <bostjan.xperia@gmail.com> wrote: