aF.
aF.

Reputation: 66757

How to make a dynamic number of horizontal BoxSizers?

I have a function that calculates the number of images that can be displayed on the screen, if there are more images than the ones that can be put on screen, I resize the images till they all can appear.

Then, I want to display them with one vertical box sizer and several horizontal box sizers!

The horizontal number of box sizers are dynamic, it can be only one or more depending on the number of images.

How can I define several box sizers and add them to the vertical box sizer?

Upvotes: 1

Views: 162

Answers (2)

aF.
aF.

Reputation: 66757

wx.GridSizer is the answer!

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882851

Why not simply make the horizontal sizers in a loop, .Adding them to the same vertical sizer? E.g.

def HorzInVert(n):
  vert = wx.BoxSizer(wx.VERTICAL)
  horizontals = []
  for i in range(n):
    horz = wx.BoxSizer(wx.HORIZONTAL)
    vert.Add(horz,1, wx.ALL, 0)
    horizontals.append(horz)
  return vert, horizontals

You can call this simple function from anywhere, it returns the vertical sizer and the list of n horizontal sizers in it -- then the caller adds stuff suitably to the horizontal sliders, an appropriate SetSizerwith the vertical sizer as the argument, and the vertical sizer's .Fit. Of course you can make it as much fancier as you want, with all sort of arguments to control exactly how the Adds are performed.

Upvotes: 3

Related Questions