title: Updating Old wxPython App: Invalid Window Calling Super/Parent Method
body: <p>I am trying to update an <a href="https://github.com/AntumDeluge/debreate" rel="nofollow noreferrer">old app</a> that was written for Python 2.7 with wxWidgets/wxPython 2.8. I am trying to make it compatible with my current system's versions of Python (3.10) &amp; wxPython (4.0).</p>
  <p>I have come across an error trying to call a super/parent method. The class is derived from <a href="https://docs.wxpython.org/wx.ScrolledWindow.html?highlight=wx%20scrolledwindow#wx.ScrolledWindow" rel="nofollow noreferrer">wx.ScrolledWindow</a>.</p>
  <p>The old code snippet is (<em>ui/panel.py starting at line 74</em>):</p>
  <pre><code>def SetScrollbars(window):
    if isinstance(window, wx.ScrolledWindow):
      window.SetScrollbars(20, 20, 0, 0)
  
  ## A wx.ScrolledWindow that sets scrollbars by default
  class ScrolledPanel(wx.ScrolledWindow, PanelBase):
    def __init__(self, parent, win_id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
        style=wx.HSCROLL|wx.VSCROLL, name=&quot;scrolledPanel&quot;):
      wx.ScrolledWindow.__init__(self, parent, win_id, pos, size, style, name)
      SetScrollbars(self)
  
    ## Override inherited method to also update the scrollbars
    def Layout(self):
      layout = wx.ScrolledWindow.Layout(self)
      self.UpdateScrollbars()
      return layout
  </code></pre>
  <p>The error is:</p>
  <pre><code>  File &quot;ui/panel.py&quot;, line 87, in Layout
      layout = wx.ScrolledWindow.Layout(self)
  wx._core.wxAssertionError: C++ assertion &quot;m_widget&quot; failed at ../src/gtk/window.cpp(2888) in DoSetSize(): invalid window
  </code></pre>
  <p>I searched for how to call parent/super methods in Python &amp; found from <a href="https://stackoverflow.com/questions/805066/how-do-i-call-a-parent-classs-method-from-a-child-class-in-python">this question</a> that Python has a <a href="https://docs.python.org/3/library/functions.html#super" rel="nofollow noreferrer">super() function</a>.</p>
  <p>So I changed line 87:</p>
  <pre><code>-    layout = wx.ScrolledWindow.Layout(self)
  +    layout = super().Layout()
  </code></pre>
  <p>The same error is reported:</p>
  <pre><code>  File &quot;/home/jordan/Development/Debreate/code/ui/panel.py&quot;, line 87, in Layout
      layout = super().Layout()
  wx._core.wxAssertionError: C++ assertion &quot;m_widget&quot; failed at ../src/gtk/window.cpp(2888) in DoSetSize(): invalid window
  </code></pre>
  <p>I suppose calling the parent/super method either way is correct. So that must not be the issue.</p>
  <p>My system's version of wxWidgets is 3.0.5.1. I found the <a href="https://github.com/wxWidgets/wxWidgets/blob/v3.0.5.1/src/gtk/window.cpp#L2888" rel="nofollow noreferrer">assertion check line in the wxWidgets source code</a>. The checking function, <a href="https://docs.wxwidgets.org/3.0/group__group__funcmacro__debug.html#ga0cf2ca7d7ff0107197e51e6b434fd0bd" rel="nofollow noreferrer">wxCHECK_RET</a>, &quot;Checks that the condition is true, and returns if not&quot;. So the window is invalid. I just don't understand why as this worked with older versions of wxWidgets/wxPython.</p>