如何在 Vertical BoxSizer 中设置间隙?

发布于 2024-12-08 04:47:38 字数 133 浏览 1 评论 0原文

如何在 Vertical BoxSizer 中设置间隙? Vertival BoxSizer 中与 GridSizer 中的 SetVGap (设置 sizer 中单元格之间的垂直间隙(以像素为单位))的类似或替代方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

春夜浅 2024-12-15 04:47:38

有多种方法可以在尺寸调整器中添加空白区域。

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

上面的代码将添加所有边都有 5 像素边框的小部件。如果您想在两个小部件之间放置一些空间,您可以执行以下操作之一:

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)

执行 sizer.Add((0,0)) 的好处是,您可以按 1(一)的比例添加它,如果您想要,这会将所有以下小部件推到底部。我用它来更好地控制小部件的放置。

另请参阅http://www.wxpython.org/docs/api/wx.Sizer-class。 html

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

╭⌒浅淡时光〆 2024-12-15 04:47:38

我假设你的意思是一个垂直框大小调整器,如下所示

wxBoxSizer * szr = new( wxVERTICAL );

以下调用将

szr->AddSpacer(10);

在Python中添加10个像素的“垂直间隙”,我想它看起来像这样

szr = wx.BoxSizer( wxVERTICAL )

... add stuff above gap

szr.AddSpacer(10)

... add stuff below gap

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
岁月流歌 2024-12-15 04:47:38

wx.BoxSizer 中没有间隙参数(正如您所说,GridSizers 中是否有)。创建间隙的方法是在小部件中设置边框。这可以通过以下样式来完成:wx.ALLwx.BOTTOM 和/或 wx.TOP

例如:

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

将在顶部和底部带有 5 点边框的框中添加一个居中的小部件(我的代码中的一个按钮)。

如果您这样写,则显示:

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)

您会得到 3 个有间隙的按钮,类似于使用 SetVGap 所获得的效果,并且您还可以通过设置 vgap 来控制插槽之间的间隔。

正如其他答案所示,您也可以在小部件之间插入分隔符以获得相同的效果,但在我看来,如果您想要相当于网格 vgap 的东西,这似乎更干净(没有额外的“sizer.add”行)。

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.

逆蝶 2024-12-15 04:47:38

中找到标题“wx.BoxSizer”

可能也很有趣:在http://zetcode.com/wxpython/layout/

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文