How can I set a space in Vertical BoxSizer?

How to set clearance in Vertical BoxSizer? What is the similar or alternative SetVGap method (which sets the vertical gap (in pixels) between cells in the sizer) in the Vertival BoxSizer in GridSizer?

+6
source share
4 answers

There are several ways to add empty space to sizer.

 sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(widget, proportion=0, style=wx.ALL, border=5) 

The above code will add a widget with a 5-pixel border on all sides. If you want to place some space between two widgets, you can do one of the following:

 sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(widget, proportion=0, style=wx.ALL, border=5) sizer.AddSpacer(10) # or sizer.Add((0,0)) sizer.Add(anotherWidget, proportion=0, style=wx.ALL, border=5) 

The good thing about doing sizer.Add ((0,0)) is that you can add it with a fraction of 1 (one) if you want, and this will cause all of the following widgets to be omitted. I use it to give me a bit more control over widget placement.

See also http://www.wxpython.org/docs/api/wx.Sizer-class.html

+9
source

I assume you mean a vertical window divider like

 wxBoxSizer * szr = new( wxVERTICAL ); 

The next call will add 10 pixels of "vertical clearance"

 szr->AddSpacer(10); 

In Python, I think it will look something like this.

 szr = wx.BoxSizer( wxVERTICAL ) ... add stuff above gap szr.AddSpacer(10) ... add stuff below gap 
+5
source

There wx.BoxSizer no gap parameter in wx.BoxSizer (is there a GridSizer, as you said). The way to create a space is to set the border in your widgets. This can be done with the styles: wx.ALL , wx.BOTTOM and / or wx.TOP .

For instance:

 szr = wx.BoxSizer(wx.VERTICAL) szr.Add(self.button_1, 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5) 

will add a centered widget (button in my code) in the field with a 5-point border above and below.

Show if you write:

 vgap = 5 szr = wx.BoxSizer(wx.VERTICAL) szr.Add(self.button_1, 0, wx.TOP, vgap) szr.Add(self.button_2, 0, wx.TOP, vgap) szr.Add(self.button_3, 0, wx.TOP, vgap) 

you get 3 buttons, similar to what you would have with SetVGap , and you can control the separation between the slots by installing vgap.

Like the other answers, you can also insert separators between your widgets to get the same effect, but it seems to me cleaner (without the extra lines "sizer.add") if what you want is equivalent to the vgap grid.

+3
source

It may also be interesting: find the heading "wx.BoxSizer" in

http://zetcode.com/wxpython/layout/

+2
source

Source: https://habr.com/ru/post/898582/


All Articles