wxpython + CollapsiblePane不起作用

时间:2017-02-08 16:12:36

标签: wxpython

我今天了解到可折叠的窗格。但我无法让它发挥作用。我得到的错误是:

"TypeError: in method 'new_CollapsiblePane', expected argument 1 of type 'wxWindow *'"

我尝试将可折叠过滤器作为“def”,作为类并包含在类main中。现在我没有想法。

这是我最近的代码:

class Main(wx.Panel):
    def __init__(self, parent=None, id=-1, notify_channel=None, **kwargs):
        wx.Panel.__init__(self, parent, id)
        "some other stuff"
       self.rightsizer.AddStretchSpacer(1)
       self.rightsizer.Add(self.listsizer, 80, wx.EXPAND)
       self.rightsizer.AddStretchSpacer(1)

       self.sizer.AddStretchSpacer(1)
       self.sizer.Add(CollapsibleFilter(self, label="Filter:"), 0, wx.EXPAND)
       self.sizer.AddStretchSpacer(1)
       self.sizer.Add(self.rightsizer, 50, wx.EXPAND)
       self.sizer.AddStretchSpacer(2)

       self.SetSizer(self.sizer)
       self.sizer.Fit(self)

class CollapsibleFilter(wx.CollapsiblePane):

    def __init__(self, notify_channel, **kwargs):
      wx.CollapsiblePane.__init__(self,wx.ID_ANY, **kwargs)
      self.notify_channel = notify_channel

      self.CollapsibleFilter=self.GetPane()


      self.filter1 = FilterBox(self.CollapsibleFilter, notify_channel=self.notify_channel)
      self.filter2 = FilterBox(self.CollapsibleFilter, notify_channel=self.notify_channel)
      self.filter3 = FilterBox(self.CollapsibleFilter, notify_channel=self.notify_channel)

      self.filter1.set_dropdown_items(browser_options.filterlist)
      self.filter1.set_dropdown_default(browser_options.default_1)
      self.filter2.set_dropdown_items(browser_options.filterlist)
      self.filter2.set_dropdown_default(browser_options.default_2)
      self.filter3.set_dropdown_items(browser_options.filterlist)
      self.filter3.set_dropdown_default(browser_options.default_3)

      #layout
      self.filtersizer = wx.BoxSizer(wx.VERTICAL)

      self.filtersizer.AddStretchSpacer(1)
      self.filtersizer.Add(self.filter1, 60, wx.EXPAND)
      self.filtersizer.AddStretchSpacer(1)
      self.filtersizer.Add(self.filter2, 60, wx.EXPAND)
      self.filtersizer.AddStretchSpacer(1)
      self.filtersizer.Add(self.filter3, 60, wx.EXPAND)
      self.filtersizer.AddStretchSpacer(1)

我希望有人可以帮助我! TX

1 个答案:

答案 0 :(得分:1)

就像任何窗口小部件类一样,它在构造时需要接收对父窗口小部件的引用。在你的CollapsibleFilter类中,当它调用超类__init__时,你没有传递父类,所以这就是它失败的原因。试试这个:

class CollapsibleFilter(wx.CollapsiblePane):
    def __init__(self, parent, notify_channel, **kwargs):
      wx.CollapsiblePane.__init__(self, parent, wx.ID_ANY, **kwargs)
      ...