...
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class UserInfoModalWindow(QDialog):
def init(self):
super(UserInfoModalWindow, self).init()
self.dialog_window = QDialog(self)
...
self.dialog_window.exec_()
...
def quit(self):
self.dialog_window.close()
...
class AcceptDialogWindow(UserInfoModalWindow):
def init(self):
super(UserInfoModalWindow, self).init()
self.accept_dialog = QDialog()
...
self.accept_button = QPushButton()
self.cancel_button = QPushButton()
...
self.connect(self.accept_button,
SIGNAL('clicked()'),
lambda: self.quit())
self.connect(self.cancel_button,
SIGNAL('clicked()'),
self.accept_dialog.close)
...
self.accept_dialog.exec_()
...
# From this method I want to call a method from a parent class
def quit(self):
self.accept_dialog.close()
return super(UserInfoModalWindow, self).quit()
当点击“取消按钮”时-仅accept_dialog关闭,是的, 但是,当单击“ accept_button”时,应关闭accept_dialog和dialog_window。
I get this error: File "app.py", line 252, in quit
return super(UserInfoModalWindow, self).quit()
AttributeError: 'super' object has no attribute 'quit'
出了什么问题?我做错了什么?
答案 0 :(得分:1)
这里:
return super(UserInfoModalWindow, self).quit()
您要
return super(AcceptDialogWindow, self).quit()
super()
第一个参数应该是当前类(至少在大多数使用情况下)。实际上super(cls, self).method()
的意思是:
self
的mro cls
cls
之后的那一类)因此super(UserInfoModalWindow, self)
中的AcceptDialogWindow
解析为UserInfoModalWindow
的父级,即QDialog
。
请注意,在Python 3.x中,您不必将任何参数传递给super()
-它会自动执行RightThing(tm)。