我在wx.Panel中有一个wx.StaticBox。静态框几乎占据了面板中没有边框的所有空间。如何在静态框周围添加边框?
一些示例代码:
self.aPanel = wx.Panel( self, wx.ID_ANY, style = wx.RAISED_BORDER )
self.aLabel = wx.StaticText( self.aPanel, -1, 'Bar' )
self.aSizer = wx.BoxSizer( wx.HORIZONTAL )
self.aSizer.Add( self.aLabel, 0, wx.ALIGN_CENTER | wx.ALL )
self.aBox = wx.StaticBox( self.aPanel, wx.ID_ANY, 'Foo' )
self.aBoxSizer = wx.StaticBoxSizer( self.aBox, wx.VERTICAL )
self.aBoxSizer.Add( self.aSizer, 0, wx.ALIGN_LEFT | wx.ALL )
self.aPanel.SetSizer( self.aBoxSizer )
答案 0 :(得分:2)
我猜可能是因为你使用的是wx.StaticBoxSizer。如果我用wx.BoxSizer替换它,则boarder参数按预期工作。这是一个最小的例子。我不知道你想要的确切布局。所以,它可能不会做你真正想要的,但我希望它有助于作为一个起点。
(编辑:根据评论修改的代码)
import wx
class myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title='Test', size=(200,200))
self.aPanel = wx.Panel(self, style = wx.RAISED_BORDER )
self.aLabel = wx.StaticText( self.aPanel, -1, 'Bar' )
self.aBox = wx.StaticBox(self.aPanel, -1, 'Foo')
self.aSizer = wx.BoxSizer( wx.HORIZONTAL )
self.aSizer.Add( self.aLabel, 0, wx.ALIGN_CENTER | wx.ALL )
self.aBoxSizer = wx.StaticBoxSizer( self.aBox, wx.VERTICAL )
self.aBoxSizer.Add( self.aSizer, 0, wx.ALIGN_LEFT | wx.ALL )
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.aBoxSizer, 1, wx.EXPAND | wx.ALL, 20)
self.aPanel.SetSizer( vbox )
self.Show()
if __name__ == '__main__':
app = wx.PySimpleApp(0)
frame = myframe()
app.MainLoop()