...
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()
当点击'cancel_button'时 - 只有accept_dialog关闭,这是正确的,但是当点击'accept_button'时 - 应该关闭accept_dialog AND 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'
有什么问题?我做错了什么?
这里:
return super(UserInfoModalWindow, self).quit()
你要:
return super(AcceptDialogWindow, self).quit()
super()
第一个参数应该是当前的类(至少对于大多数用例)。实际上super(cls, self).method()
意味着:
self
的mrocls
cls
之后)所以在super(UserInfoModalWindow, self)
的AcceptDialogWindow
解决了UserInfoModalWindow
的父母,这是QDialog
。
请注意,在Python 3.x中,您不必将任何参数传递给super()
- 它将自动执行RightThing(tm)。