Explanation of the code of the .py file that calls .ui conversion in PyQt5

1. Commonly used writing

from PyQt5.QtWidgets import QApplication,QMainWindow
import sys
from Ui_firstMainwindow import *

class MyMainWindow(QMainWindow,Ui_MainWindow):
	# 这一部分感觉不好理解
    def __init__(self,parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.setupUi(self)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWindow = MyMainWindow()
    myWindow.show()
    sys.exit(app.exec_())

2. Today I saw another way of writing shared by a great god

from PyQt5.QtWidgets import QApplication,QMainWindow
import sys
from Ui_firstMainwindow import *



if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 实例化一个主窗口
    myWindow = QMainWindow()
    # 实例化.ui转换后的py文件
    ui_main_window = Ui_MainWindow()
    # 调用转换后的py文件实例对象方法setupUi,并继承QMainwindow的实例对象(这里算不算多态我还说不太清楚)
    ui_main_window.setupUi(myWindow)
    # 展示窗口
    myWindow.show()
    sys.exit(app.exec_())

I feel that this kind of logic is better, the first method, if there is a great god who can help explain it if there is time, it is greatly appreciated

Guess you like

Origin blog.csdn.net/baidu_20313315/article/details/112956113