Trying to instantiate a wx.HeaderCtrl and getting an unfamiliar error


I'm trying to create a wx.HeaderCtrl object and I'm getting an error that I haven't been able to find on google. This is the code:

import wx

class MyApp(wx.App):
    def __init__(self):
        self.frame = MyFrame(parent=None, title="Configuration")

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super().__init__(parent, title=title, size=(1600, 800))
        self.configpanel = MyPanel(self)

class MyPanel(wx.Panel):
    def __init__(self, parent):

        foo = MyHeaderCtrl(self)

class MyHeaderCtrl(wx.HeaderCtrl):
    def __init__(self, parent):

if __name__ == "__main__":
    app = MyApp()

My problem is in the My Panel class, where I try to instantiate the HeaderCtrl foo, and then create it. No matter how I organize those, or what kind of window or panel I set as the parent of Create I get this error:

Traceback (most recent call last):

File "C:/_Code/Projects/Personal/BigOlTimeline/Python/", line 32, in app = MyApp()

File "C:/_Code/Projects/Personal/BigOlTimeline/Python/", line 7, in init self.frame = MyFrame(parent=None, title="Configuration")

File "C:/_Code/Projects/Personal/BigOlTimeline/Python/", line 14, in init self.configpanel = MyPanel(self)

File "C:/_Code/Projects/Personal/BigOlTimeline/Python/", line 22, in init foo = MyHeaderCtrl(self).Create(wx.Window())

wx._core.wxAssertionError: C++ assertion ""!m_hWnd"" failed at ....\src\msw\window.cpp(3971) in wxWindow::MSWCreate(): window can't be recreated

Process finished with exit code -1073741819 (0xC0000005)

This is my first introduction to implementing abstract classes, and having to use a separate Create() instead of just the init, so I'm sure it's something simple but I had a lot of trouble finding anything similar online. Any help would be greatly appreciated.


1 Answer


In wxWidgets, you can't call Create() if you have already created a window using its non-default constructor. In your code, you already create the window by calling its __init__ in your own version, so you must not call Create() later -- just remove this line to fix the problem.

answered on Stack Overflow Mar 7, 2020 by VZ.

User contributions licensed under CC BY-SA 3.0