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):
super().__init__()
self.frame = MyFrame(parent=None, title="Configuration")
self.frame.Show()
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):
super().__init__(parent)
foo = MyHeaderCtrl(self)
foo.Create(self)
class MyHeaderCtrl(wx.HeaderCtrl):
def __init__(self, parent):
super().__init__(parent)
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
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/test.py", line 32, in app = MyApp()
File "C:/_Code/Projects/Personal/BigOlTimeline/Python/test.py", line 7, in init self.frame = MyFrame(parent=None, title="Configuration")
File "C:/_Code/Projects/Personal/BigOlTimeline/Python/test.py", line 14, in init self.configpanel = MyPanel(self)
File "C:/_Code/Projects/Personal/BigOlTimeline/Python/test.py", 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.
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.