0
#!/usr/bin/python
import sys
from PyQt4 import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__() # what the meaning of this line
self.initUI()
def initUI(self):
lbl1 = QtGui.QLabel('ZetCode', self)
lbl1.move(15, 10)
lbl2 = QtGui.QLabel('tutorials', self)
lbl2.move(35, 40)
lbl3 = QtGui.QLabel('for programmers', self)
lbl3.move(55, 70)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Absolute')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
或者在'__init__'内有''super''和其他几十个其他问题已经存在,请在询问之前做一些研究。 – jonrsharpe
所有你真正需要知道的是,在你的例子中,它或多或少等同于'QWidget .__ init __(self)'(你可以很容易地为自己测试)。当创建一个子类的实例时,python会自动调用基类的'__init__' - 除非你已经覆盖它,就像你的例子。通常,如果在子类中重写'__init__',则还需要显式调用基类'__init__'。还有其他原因需要专门使用'super'来完成,但严格来说,它们并不适用于PyQt,因为它大多使用单一继承。 – ekhumoro