Reputation: 49537
I am trying to learn PyQt
on my own from rapid gui programming with python and qt
and having trouble understanding the meaning/requirement
of below line of code mentioned in one of the example in the book.
class Form(QDialog):
def __init__(self,parent=None):
super(Form,self).__init__(parent) # Trouble understanding here
So, my question is what is the need of super(Form,self).__init__(parent)
or what purpose it is trying to full fill in this code.
Upvotes: 1
Views: 269
Reputation: 137310
Take a look at the documentation of super()
:
Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.
So basically this line of code:
super(Form,self).__init__(parent)
finds the "closest" set __init__()
method in classes from which current class (Form
) is inheriting and initiates self
object using this method and passing parent
as the first argument.
Upvotes: 2