wx.StaticBox 大小参数不受尊重
我正在尝试创建一个具有恒定大小的 wx.StaticBox
,无论其中小部件的大小如何。所以我有一个包含以下代码的面板:
box = wx.StaticBox(self, -1, 'BoxTitle', size=(200, 200))
bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
text = wx.StaticText(self, -1, 'Text')
bsizer.Add(text)
border = wx.BoxSizer()
border.Add(bsizer)
self.SetSizer(border)
但是,该框只是将 StaticText
小部件包裹在其中,而不是坚持指定的 200x200 大小。如何使盒子符合硬编码尺寸?
I'm trying to create a wx.StaticBox
having a constant size, regardless to the size of the widget within. So I have a panel containing the following code:
box = wx.StaticBox(self, -1, 'BoxTitle', size=(200, 200))
bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
text = wx.StaticText(self, -1, 'Text')
bsizer.Add(text)
border = wx.BoxSizer()
border.Add(bsizer)
self.SetSizer(border)
However, the box simply wraps the StaticText
widget within, instead of sticking to the specified 200x200 size. How do I make the box conform to a hard-coded size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在创建
StaticBox
后添加以下内容,它将强制您调整大小:请注意,
StaticText
框不会换行其文本,因此如果您的文本比StaticBox
它将延伸到框的边缘之外(至少在 OS X 上它会这样做,在 Windows 上的行为可能有所不同)。更新:
在 Windows 上,大小调整的行为有很大不同 -
StaticBox
只是围绕文本缩小。尽管我同意 bogdan 的观点,即使用
SetMinSize
或SetMaxSize
显式设置窗口大小可能不是一个好主意(例如,如果系统字体大小发生变化并且内容不再适合(您设置的大小限制),StaticText 控件会缩小到其内容的大小,并且看起来会拉动所有内容,除非您明确地对其容器施加大小限制。我怀疑您唯一的选择是在框控件上使用
SetMaxSize
或SetMinSize
,或者尝试除StaticText
之外的其他控件选项。您可以尝试使用HtmlWindow
作为替代方案。If you add the following after creating your
StaticBox
it will force the size for you:Note that a
StaticText
box does not wrap its text, so if your text is wider than theStaticBox
it will extend beyond the edge of the box (as least on OS X it does this, may behave differently on Windows).Update:
On Windows the sizing behaves much differently - the
StaticBox
just shrinks around the text.Although I agree with bogdan that explicitly setting a window size with
SetMinSize
orSetMaxSize
is probably not a good idea (e.g. if system font size changes and the contents no longer fits nicely into the size constraints you've set), the StaticText control shrinks to the size of its contents and appears to pull everything with it unless you explicitly force size limits on its container.I suspect your only option here is either to use
SetMaxSize
orSetMinSize
on your box control, or try other control options other than aStaticText
. You could try theHtmlWindow
as an alternative.