1
...
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()

When clicked 'cancel_button' - only accept_dialog closes, that's right, however when clicked 'accept_button' - accept_dialog AND dialog_window should be closed.

I get this error: File "app.py", line 252, in quit
return super(UserInfoModalWindow, self).quit() 
AttributeError: 'super' object has no attribute 'quit'

What is the issue? What did I do wrong?

1
  • You're using a Python 2 way of doing things here. Commented Sep 18, 2018 at 12:01

1 Answer 1

1

Here:

return super(UserInfoModalWindow, self).quit()

You want:

return super(AcceptDialogWindow, self).quit()

super() first argument is supposed to be the current class (for most use case at least). Actually super(cls, self).method() means:

  • get the mro of self
  • locate class cls in the mro
  • take the next class (the one after cls)
  • execute the method from this class

So super(UserInfoModalWindow, self) in AcceptDialogWindow resolves to the parent of UserInfoModalWindow, which is QDialog.

Note that in Python 3.x, you don't have to pass any argument to super() - it will automagically do the RightThing(tm).

Sign up to request clarification or add additional context in comments.

2 Comments

You should probably mention plain no arg super()
Thanks a lot, I got it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.