@zoro I am not sure why @Axel_Erfurt continues to propagate bad code as he is fully aware by now that using Super() is more dangerous than using explicit declarations. Further it is not easier since you have to make sure to code in a particular way as to compensate for the 3 known issues that using Super() creates. Finally Super() was initially created to fix an very rare issue with using the explicit methodology and if you are not using it for this reason then you are creating more issues than you are fixing.
Next @Axel_Erfurt is also aware that
Next do not pass
Here is a cleaned up and proper version of Axel_Erfurt's example hopefully he will start providing more quality code in the future
Next @Axel_Erfurt is also aware that
sys.exit(app.exec_())
is PyQt4 coding and that PyQt5 now uses app.exec()
and further that QApplication(sys.argv)
is not quality since QApplication([])
is the better way to use this and then IF you happen to be using Command Line arguments you employ the argparser library as it handles Command Line arguments much more cleanlyNext do not pass
self
to QLabel that is totally unnecessary and completely unused in this case.Here is a cleaned up and proper version of Axel_Erfurt's example hopefully he will start providing more quality code in the future
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel,QPushButton class MyForm(QWidget): def __init__(self): # Do Not use Super() unless you know the 3 issues you have to protect # against when using it and further it is only needed if you are create # a program that has the rare issue it was created to handle QWidget.__init__(self) # This should be set in here self.setWindowTitle("MyForm") Left = 100; Top = 100; Wdth = 200; Hght = 100 self.setGeometry(Left, Top, Wdth, Hght) self.btnClick = QPushButton('Click') self.btnClick.clicked.connect(self.Clicked) # self. is needed whenever you may need to reference # definitely needed here with QLabel as you plan to # reference it later on self.lblAOS = QLabel('AOS') vbox = QVBoxLayout() vbox.addWidget(self.lblAOS) vbox.addWidget(self.btnClick) self.setLayout(vbox) def Clicked(self): self.lblAOS.setText("Button Clicked") if __name__ == '__main__': MainEvntHndlr = QApplication([]) MainApp = MyForm() MainApp.show() MainEvntHndlr.exec()P.S. @Axel_Erfurt if you need help with creating quality python-Qt5 code I am more than willing to help just shoot me a PM.