我试图创建一个wx.HeaderCtrl对象,但我得到了一个在google上找不到的错误。代码如下:
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()
我的问题是在MyPanel类中,我尝试实例化HeaderCtrl foo,然后创建它。无论我如何组织它们,或者我将什么类型的窗口或面板设置为Create的父窗口或面板,都会出现以下错误:
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)
这是我第一次介绍如何实现抽象类,并且必须使用一个单独的Create(),而不仅仅是init,因此我确信这很简单,但我在网上很难找到类似的东西。 任何帮助都将不胜感激
在wxWidgets中,如果已经使用非默认构造函数创建了窗口,则不能调用
Create()
。在您的代码中,您已经通过在自己的版本中调用其__init__
来创建窗口,因此以后不能调用Create()
,只需删除此行即可解决问题相关问题 更多 >
编程相关推荐