Python Forum
Why is there an __init__ statement within the __init__ definition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is there an __init__ statement within the __init__ definition
#1
Hi there,

could someone please explain why with this bit of code I have copied, there is a second init statement in the init definition:
#!/usr/bin/python3

import sys
from PyQt4 improt QtGui, QtCore

class Window(QtGui.QMainWindow):
    def __init___(self, parent=None):
        QtGui.QWidget.__init__(self, parent)                        # <--  this line of code, what does it do???
        self.setGeometry(0, 0, 1920, 1080)
        self.home()

    def  home(self):
        self.lbl = QtGui.QLabel("Hello World!", self)
        self.lbl.setGeometry(QtCore.QRect(800, 30, 1161, 101))
        self.show()

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main_window = Window()
    sys.exit(app.exec_))
So this seems to be the complete minimum code required in order to get a window and a label using object oriented programming. I also don't understand why I am having to call the home method from the init method, that doesn't make sense either, but if I take that out, then the code runs without error, but there is no window, and no way to stop the script either. If someone could help explain this that would really help.

I'm really struggling with OOP, and have been for about 6 months (currently I am being paid to learn to program, so when I say 6 months, that's 8 hours a day for six months) to the point I can only copy code, I can't write my own, is this normal?
Reply


Messages In This Thread
Why is there an __init__ statement within the __init__ definition - by iFunKtion - Feb-06-2017, 12:12 PM
RE: t - by buran - Feb-06-2017, 12:17 PM
RE: t - by Kebap - Feb-06-2017, 12:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 300 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  __init__() got multiple values for argument 'schema' dawid294 4 2,568 Jan-03-2024, 09:42 AM
Last Post: buran
  mutable argument in function definition akbarza 1 512 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 754 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 612 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  Initiating an attribute in a class __init__: question billykid999 8 1,435 May-02-2023, 09:09 PM
Last Post: billykid999
Question __init__ of Child Class zero_fX0 4 1,803 Mar-22-2023, 05:23 PM
Last Post: deanhystad
  [split] Explain the python code in this definition Led_Zeppelin 1 770 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Explain the python code in this definition Led_Zeppelin 1 1,127 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 2,019 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020