I have a layout for an app that has a panel that places 3 static boxes (nodes) per row, and then keeps going until the dictionary of nodes is out. I figured out the flex grid sizer to do so (wrapped by regular boxsizers to add padding above and on the sides. Everything works great, until I start to add content to the static boxes. I do so with static box sizers and everything ends up in the boxes, but it shrinks the vgap of my flexgridsizer? Or something else is going on, but definitely they scrunch together vertically. What am I doing wrong? Here's the pertinent code:

   vgap = 35
   hgap = 20
   nodesPerRow = 3
   nodeHeight = 100
   numRows = len(self.addArgs["khzObj"].nodes) / nodesPerRow

   outSizer = wx.BoxSizer(wx.VERTICAL)
   outHSizer = wx.BoxSizer(wx.HORIZONTAL)
   outSizer.AddStretchSpacer(1)
   outHSizer.AddStretchSpacer(1)
   sizer = wx.FlexGridSizer(rows=numRows, cols=nodesPerRow, vgap=vgap, hgap=hgap)
   dummySpace = wx.StaticText(nodeTab, wx.ID_ANY, "", size=(0,nodeHeight))

   for index, (key, value) in enumerate(self.addArgs["khzObj"].nodes.items(), start=1):
       self.nodeBoxes[key] = wx.StaticBox(nodeTab, wx.ID_ANY, value.name, size=(0,nodeHeight))
       boxSizer = wx.StaticBoxSizer(self.nodeBoxes[key], wx.VERTICAL)
       nodeInfo = "Node ID: {id}".format(id=value.id)
       nodeIdText = wx.StaticText(nodeTab, wx.ID_ANY, nodeInfo)
       nodeStateText = wx.StaticText(nodeTab, wx.ID_ANY, value.currentStateStr)
       boxSizer.Add(nodeIdText, proportion=1, flag=wx.ALIGN_CENTER)
       boxSizer.Add(nodeStateText, proportion=1, flag=wx.ALIGN_CENTER)
       sizer.Add(boxSizer, flag=wx.EXPAND)

   while not index % nodesPerRow == 0:
       sizer.Add(dummySpace, flag=wx.EXPAND)
       index = index + 1 # this while fills an unfilled row

   for i in range(nodesPerRow):
       sizer.AddGrowableCol(i,1)

   outHSizer.Add(sizer, flag=wx.EXPAND, proportion=15)
   outHSizer.AddStretchSpacer(1)
   outSizer.Add(outHSizer, flag=wx.EXPAND, proportion=15)
   nodeTab.SetSizer(outSizer)
   nodeTab.SetAutoLayout(1)
   nodeTab.SetupScrolling()

nodeTab is a ScrolledPanel

I figured this out. It turns out that, before adding the staticboxsizers, the vgap would start at the bottom of the box -- after adding the staticboxsizers, the vgap started at the bottom of the last statictext. This made it appear the boxes had moved together when actually I just needed to increase the vgap.

It's been a while since I used wxPython, so thank you for the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.