Creating an automatic wrapping layout
Sizers allow the dynamic positioning and resizing of controls, though this layout is still typically on a fixed grid or in a single direction at a time, similar to BoxSizer
. If you wish to allow controls to wrap and flow in both the horizontal and vertical directions as the space allows, you can use WrapSizer
, which allows only this. It works much like BoxSizer
in that it has a primary direction of layout, but as the space in the primary direction is used up, the sizer automatically adds new columns or rows in the secondary direction. In this recipe, we will have a quick introduction to using WrapSizer
.
How to do it…
You need to perform these steps:
The usage is basically similar to
BoxSizer
; so, let's just set up a panel with 15 buttons on it to explore how thissizer
works through the following code:class WrappingPanel(wx.Panel): def __init__(self, parent): super(WrappingPanel, self).__init__(parent) sizer = wx.WrapSizer(wx.HORIZONTAL...