When should I use "parent=None" in __ini__ and "parent" in super()

When should I use "parent=None" in __ini__ and "parent" in super() Hi Guys I've sent this question to other Python community but didn't get any answer. I hope that here I can get an explanation of how to use parent in the Python OOP. I'm writing since almost one-year codes in Python, using TKinter and PyQt5. I'm somehow able to writes GUIs in both of them. But since I'm using more Pyqt5 and using classes with initialization and super() constructs, and also I saw lots of videos and examples of coding them, I still don’t know exactly how and when should I use the parent in __init()__ and super() construct. For example, the following lines use "parent=None" in the __init__ construct and "parent" in the super() construct. And sometimes I do not see any of them in these two constructs. :::::::::::::::::::::::::::::::::::::::::::::::: class MyClass1(QWidget): def __init__(self, name, parent=None): super(MyClass1, self).__init__(parent) print(self.parent().test) :::::::::::::::::::::::::::::::::::::::::::::::: And sometimes without "parent" like the following: :::::::::::::::::::::::::::::::::::::::::::::::: class MyClass2(QWidget): def __init__(self, name): super(MyClass2, self).__init__() print(self.parent().test) :::::::::::::::::::::::::::::::::::::::::::::::: Could anyone explain this to me when and for which action I have to use the first one "MyClass1" and when the second one "MyClass2"? Mohsen

Mohsen, in deutschen Usergruppen solltest du dir die Arbeit machenm, auch deutsch zu schreiben. Die Antwort auf diese Frage habe ich dir schon in der vorherigen Mail gegeben. Cheers, Pete Am Freitag, 8. Oktober 2021, 12:17:15 CEST schrieb Mohsen Owzar:
When should I use "parent=None" in __ini__ and "parent" in super() Hi Guys I've sent this question to other Python community but didn't get any answer. I hope that here I can get an explanation of how to use parent in the Python OOP.
I'm writing since almost one-year codes in Python, using TKinter and PyQt5. I'm somehow able to writes GUIs in both of them.
But since I'm using more Pyqt5 and using classes with initialization and super() constructs, and also I saw lots of videos and examples of coding them, I still don’t know exactly how and when should I use the parent in __init()__ and super() construct.
For example, the following lines use "parent=None" in the __init__ construct and "parent" in the super() construct. And sometimes I do not see any of them in these two constructs.
class MyClass1(QWidget): def __init__(self, name, parent=None): super(MyClass1, self).__init__(parent) print(self.parent().test)
And sometimes without "parent" like the following:
class MyClass2(QWidget): def __init__(self, name): super(MyClass2, self).__init__() print(self.parent().test)
Could anyone explain this to me when and for which action I have to use the first one "MyClass1" and when the second one "MyClass2"?
Mohsen _______________________________________________ python-de Mailingliste -- python-de@python.org Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an python-de-leave@python.org https://mail.python.org/mailman3/lists/python-de.python.org/ Mitgliedsadresse: hpj@urpla.net

Hans-Peter Jansen schrieb am Freitag, 8. Oktober 2021 um 18:11:14 UTC+2:
Mohsen,
in deutschen Usergruppen solltest du dir die Arbeit machenm, auch deutsch zu schreiben.
Die Antwort auf diese Frage habe ich dir schon in der vorherigen Mail gegeben.
Cheers, Pete Am Freitag, 8. Oktober 2021, 12:17:15 CEST schrieb Mohsen Owzar:
When should I use "parent=None" in __ini__ and "parent" in super() Hi Guys I've sent this question to other Python community but didn't get any answer. I hope that here I can get an explanation of how to use parent in the Python OOP.
I'm writing since almost one-year codes in Python, using TKinter and PyQt5. I'm somehow able to writes GUIs in both of them.
But since I'm using more Pyqt5 and using classes with initialization and super() constructs, and also I saw lots of videos and examples of coding them, I still don’t know exactly how and when should I use the parent in __init()__ and super() construct.
For example, the following lines use "parent=None" in the __init__ construct and "parent" in the super() construct. And sometimes I do not see any of them in these two constructs.
class MyClass1(QWidget): def __init__(self, name, parent=None): super(MyClass1, self).__init__(parent) print(self.parent().test)
And sometimes without "parent" like the following:
class MyClass2(QWidget): def __init__(self, name): super(MyClass2, self).__init__() print(self.parent().test)
Could anyone explain this to me when and for which action I have to use the first one "MyClass1" and when the second one "MyClass2"?
Mohsen _______________________________________________ python-de Mailingliste -- pyth...@python.org Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an python-...@python.org https://mail.python.org/mailman3/lists/python-de.python.org/ Mitgliedsadresse: h...@urpla.net
Danke Hans-Peter Ich habe gerade in der anderen Frage alles auf Deutsch vertieft erklärt und meine Frage noch einmal am Ende auf Deutsch gebracht. Gruss Mohsen
participants (2)
-
Hans-Peter Jansen
-
Mohsen Owzar