将 BoxSizer 放在其面板的中间
我编写了一些显示 wx.Frame 的代码,其中有一个 wx.Panel,其中有一个 jpg。 jpg 与框架大小相同,因此当程序启动时,用户会看到覆盖整个窗口的图片。覆盖在这张图片的顶部,并且在面板的中心我想放置一个包含各种小部件的wx.BoxSizer。到目前为止,我已经看到了大小调整器,但是,尽我所能,我无法将其从面板的最左上角移动到中心。毫无疑问,有很多涉及网格和边框的迂回方法,但在我开始这条道路之前,我想知道我是否错过了一些简单的东西,并且有一个命令可用于在小部件中定位面板的指定部分。
附:我也知道我可以使用绝对定位来做到这一点,但我希望能够调整窗口大小,同时将大小调整器保持在其中心。
I've written some code which displays a wx.Frame, within which there is a wx.Panel, within which there is a jpg. The jpg is the same size as the frame, so that when the program starts up the user is presented with a picture covering the whole of the window. Overlayed over the top of this picture, and in the centre of the panel I want to put a wx.BoxSizer containing various widgets. So far I've got the sizer visible but, try as I might, I cannot shift it from the uppermost lefthand corner of the panel to the center. No doubt there are many round-about ways of doing this involving grids and borders, but before I set off down this path, I was wondering if I'm missing something simple and there is a command that can be used to position in widget in a specified part of a panel.
ps. I also know I could do this using absolute positioning, but I want to be able to resize the window while keeping the sizer at its centre.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您看不到尺寸测量器。但无论如何,您并没有真正将尺寸调整器居中。您可以将小部件置于尺寸调整器的中心。因此,当您将小部件添加到大小调整器时,您需要执行以下操作:
现在,这只会将其水平居中。如果您希望它位于面板的正中心,则创建另一个水平定向的 BoxSizer,并将第一个大小调整器添加到第二个大小调整器,使其也居中。
Normally, you can't see a sizer. But regardless, you don't really center a sizer. You center the widgets INSIDE the sizer. So when you add a widget to the sizer, you'd want to do something like this:
Now, that will only center it horizontally. If you want it in the very center of the panel, then create another BoxSizer that is oriented horizontally and add the first sizer to the second one, centering it too.