开发者

How to make a dynamic number of horizontal BoxSizers?

开发者 https://www.devze.com 2023-01-05 19:46 出处:网络
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 appe

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 t开发者_开发问答he vertical box sizer?


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.


wx.GridSizer is the answer!

0

精彩评论

暂无评论...
验证码 换一张
取 消