Python:wxPython:水平拉伸 StaticBox 以适合框架
如何拉伸静态框以水平放置在框架上?
代码:
class XPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.box = wx.StaticBox(self, -1, "X CONTROL PANEL")
self.bsizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
self.t = wx.StaticText(self, -1, "X command: ")
self.cmdtext = wx.TextCtrl(self, -1, "")
self.itpsend_btn = wx.Button(self, -1, " Send ")
self.bsizer.Add(self.t, 0, wx.TOP|wx.LEFT, 10)
self.bsizer.Add(self.cmdtext, 0 , wx.ALL|wx.EXPAND)
self.bsizer.Add(self.itpsend_btn, 0, wx.ALL|wx.CENTER)
self.border = wx.BoxSizer()
self.border.Add(self.bsizer, -1, wx.EXPAND|wx.ALL, 25)
self.SetSizer(self.border)
我得到这个:
但我希望它能被拉伸以适合框架。
请各位赐教。谢谢。
How do I stretch a static box to fit horizontally on the frame?
Code:
class XPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.box = wx.StaticBox(self, -1, "X CONTROL PANEL")
self.bsizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
self.t = wx.StaticText(self, -1, "X command: ")
self.cmdtext = wx.TextCtrl(self, -1, "")
self.itpsend_btn = wx.Button(self, -1, " Send ")
self.bsizer.Add(self.t, 0, wx.TOP|wx.LEFT, 10)
self.bsizer.Add(self.cmdtext, 0 , wx.ALL|wx.EXPAND)
self.bsizer.Add(self.itpsend_btn, 0, wx.ALL|wx.CENTER)
self.border = wx.BoxSizer()
self.border.Add(self.bsizer, -1, wx.EXPAND|wx.ALL, 25)
self.SetSizer(self.border)
I'm getting this:
But I would like it to be strecthed in wide to fit the frame.
Please educate. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 XPanel 是正确的。您的问题不在 XPAnel 中,而是在容纳此面板和其他面板的框架中(从您的图像中至少有一个附加面板)。
在框架中,您必须告诉面板扩展并适合整个框架。因此,您必须使用 wx.EXPAND,如下所示:
Your XPanel is correct. Your problem is not in XPAnel but in the frame that holds this and other panels (from your image there is at least and additional panel).
Is in the frame that you must tell the panel to expand and fit the full frame. So , you must use wx.EXPAND as shown here: