gpt4 book ai didi

python - UI 类继承,super() 无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 19:02:19 25 4
gpt4 key购买 nike

存在一个 wxwidgets UI 类,如下所示:

class mainFrame ( wx.Frame ):
def __init__( self, parent ):
# Constructor code
# ...
# ...
# Virtual event handlers, overide them in your derived class
def about_click( self, event ):
event.Skip()
def search_perform( self, event ):
event.Skip()
def new_note_event( self, event ):
event.Skip()
def save_note_event( self, event ):
event.Skip()

我能够直接构造此类的实例并填写事件 stub ,并且它可以工作,但我确信我根本不应该更改 UI 代码文件,而是将其用作我的基类。

我尝试使用

class Main(mainFrame):
def __init__(self):
super(mainFrame, self).__init__(self, None)

上面的方法不起作用。

最佳答案

现在已经修复了。 super() 调用正在起作用。当我通过名称引用父类时,它起作用了。

我使用 UI 类的方式是

class Main(mainFrame):
def __init__(self):
mainFrame.__init__(self, None) # using super().__init__(self, None) fails
def about_click( self, event ):
print("AboutDialog")

def main():
app = wx.PySimpleApp(0)
frame = Main()
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

if __name__ == '__main__':
main()
<小时/>

super() 对于旧式类根本不起作用。它仅适用于 new-style classes它继承自 object 或其他新式类。

关于python - UI 类继承,super() 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15730015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com