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, .Add
ing 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 SetSizer
with 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 Add
s are performed.
wx.GridSizer is the answer!
精彩评论