我正在为笔记本创建一个面板,我需要添加一个sizer。但是,当我运行我的代码时:
class HomePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
[...Widget Code...]
self.verticalsizer = wx.BoxSizer(wx.VERTICAL)
self.verticalsizer.AddStretchSpacer(prop=1)
self.verticalsizer.Add(self.text, flag=wx.ALIGN_CENTER | wx.BOTTOM, border=30)
self.verticalsizer.Add(self.text1, flag=wx.ALIGN_CENTER | wx.BOTTOM, border=20)
self.verticalsizer.AddStretchSpacer(prop=1)
HomePanel.SetSizer(self.verticalsizer)
HomePanel.Layout()
我得到一个关于SetSizer()行的类型错误:
TypeError: unbound method SetSizer() must be called with HomePanel instance as first argument (got BoxSizer instance instead)
我不确定我还能将SetSizer()分配给哪个,但由于这不起作用,我也被卡住了。有没有办法绕过这个或做得更好?
答案 0 :(得分:1)
而不是:
HomePanel.SetSizer(self.verticalsizer)
HomePanel.Layout()
使用self:
self.SetSizer(self.verticalsizer)
self.Layout()