WxPython,包含滚动的可折叠窗格 Window

WxPython, Collapsible Pane containing Scrolled Window

我正在尝试创建一个可折叠窗格,它也是可滚动的,用于当包含的按钮列表大于屏幕时。所以我在窗格中放了一个 ScrolledWindow - 并得到了这个错误:

Gtk-WARNING: Attempting to add a widget with type GtkScrolledWindow to a GtkExpander, but as a GtkBin subclass a GtkExpander can only contain one widget at a time; it already contains a widget of type wxPizza

什么,他们不喜欢披萨? :) 我第一次读到它,让我觉得它们是不兼容的小部件,因为它们可能都是 GtkExpander 类型。但是这个问题 - - 似乎同时使用了两种小部件类型。有一些差异 - 首先,他们将 CollapsiblePane 放在 ScrolledWindow 中,其次,它实际上是一个 PyCollapsiblePane,来自 WxPython 的 AGW 库。

那么是否有可能通过一些小部件的组合来拥有一个可折叠的对象,当展开时,它包含一个滚动的对象列表?如果是这样,怎么办?或者这两个小部件只是不兼容(按此顺序)?

找到问题了。原来 Collapsible-Pane 有一个内面板,专供儿童使用。

class BadCollapsingPanel(wx.CollapsiblePane):
def __init__(self, parent):
    super().__init__(parent, wx.ID_ANY, style=wx.SUNKEN_BORDER)
    self.parent = parent
    self.inner_pane = self.GetPane()
    self.inner_pane.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    # self.very_bad_panel = ScrollingPanel(self)  # Breaks
    self.very_bad_panel = ScrollingPanel(self.inner_pane)  # Works