Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can set gap in Vertical BoxSizer?

How can I set gap in Vertical BoxSizer? What's in the Vertival BoxSizer the similar or alternative method of SetVGap (which sets the vertical gap (in pixels) between the cells in the sizer) in GridSizer?

like image 449
G-71 Avatar asked Oct 04 '11 12:10

G-71


4 Answers

There are several ways to add blank space in a sizer.

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

The code above will add the widget with a 5 pixel border on all sides of it. If you want to put 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 nice thing about doing sizer.Add((0,0)) is that you can add it with a proportion of 1 (one) if you want and that will push all the following widgets to the bottom. I use it to give me a little more control over widget placement.

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

like image 93
Mike Driscoll Avatar answered Oct 15 '22 14:10

Mike Driscoll


I assume you mean a vertical box sizer, like so

wxBoxSizer * szr = new( wxVERTICAL );

The following call will add 10 pixels of 'vertical gap'

szr->AddSpacer(10);

In Python, I guess it would look something like this

szr = wx.BoxSizer( wxVERTICAL )

... add stuff above gap

szr.AddSpacer(10)

... add stuff below gap
like image 31
ravenspoint Avatar answered Oct 15 '22 15:10

ravenspoint


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

For example:

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 (a button in my code) in the Box with 5-points border at the top and bottom.

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 gapped similarly to what you would have with SetVGap and you can aswell control the separation between slots by setting vgap.

As other answers indicate you can also insert separators between your widgets to obtain the same effect but this seems to me cleaner (no addditional "sizer.add" lines) if what you want is something equivalent to grids vgap.

like image 5
joaquin Avatar answered Oct 15 '22 15:10

joaquin


May also be interesting : find the title "wx.BoxSizer" in

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

like image 2
Louis Avatar answered Oct 15 '22 15:10

Louis