简体   繁体   English

如何在Vertical BoxSizer中设置差距?

[英]How I can set gap in Vertical BoxSizer?

How can I set gap in Vertical BoxSizer? 如何在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? Vertival BoxSizer中有什么相似或替代的SetVGap方法(它设置SetVGap单元格中单元格之间的垂直间隙(以像素为单位))?

There are several ways to add blank space in a sizer. 有几种方法可以在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. 上面的代码将添加小部件,其四周都有一个5像素的边框。 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. 执行sizer.Add((0,0))的好处是,如果需要,可以将其添加为1(一)的比例,并将所有以下小部件推送到底部。 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 另见http://www.wxpython.org/docs/api/wx.Sizer-class.html

I assume you mean a vertical box sizer, like so 我猜你的意思是一个垂直盒子大小,就像这样

wxBoxSizer * szr = new( wxVERTICAL );

The following call will add 10 pixels of 'vertical gap' 以下调用将添加10个像素的“垂直间隙”

szr->AddSpacer(10);

In Python, I guess it would look something like this 在Python中,我想它看起来像这样

szr = wx.BoxSizer( wxVERTICAL )

... add stuff above gap

szr.AddSpacer(10)

... add stuff below gap

There is no gap parameter in wx.BoxSizer s (do there is in GridSizers as you said). 有一个在没有间隙参数wx.BoxSizer秒(做存在GridSizers像你说的)。 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 . 这可以使用样式来完成: wx.ALLwx.BOTTOM和/或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. 将在Box中添加一个居中的小部件(我的代码中的一个按钮),顶部和底部有5个点的边框。

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. 你可以使用与SetVGap相同的3个按钮,你可以通过设置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. 正如其他答案所示,您也可以在窗口小部件之间插入分隔符以获得相同的效果,但这似乎更清晰(没有附加的“sizer.add”行),如果您想要的是与网格vgap相同的东西。

May also be interesting : find the title "wx.BoxSizer" in 也可能很有趣:找到标题“wx.BoxSizer”

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM