Using QTdesinger involves an interface. Roughly as follows
Select the saved ui file and open it with PyUic to view the code as follows
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'test.ui'## Created by: PyQt5 UI code generator 5.15.4## WARNING: Any manual changes made to this file will be lost when pyuic5 is# run again. Do not edit this file unless you know what you are doing.from PyQt5 import QtCore, QtGui, QtWidgetsclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(390, 398)self.lineEdit = QtWidgets.QLineEdit(Form)self.lineEdit.setGeometry(QtCore.QRect(70, 50, 231, 31))self.lineEdit.setObjectName("lineEdit")self.lineEdit_2 = QtWidgets.QLineEdit(Form)self.lineEdit_2.setGeometry(QtCore.QRect(70, 110, 231, 31))self.lineEdit_2.setObjectName("lineEdit_2")self.pushButton = QtWidgets.QPushButton(Form)self.pushButton.setGeometry(QtCore.QRect(70, 170, 231, 31))self.pushButton.setObjectName("pushButton")self.retranslateUi(Form)QtCore.QMetaObject.connectSlotsByName(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "Form"))self.lineEdit.setText(_translate("Form", "Account"))self.lineEdit_2.setText(_translate("Form", "Password"))self.pushButton.setText(_translate("Form", "Login"))
It is found that there is only one class in it. If you run the class, the interface you just drew will definitely not pop up
So you need to write some code to load this class, and then display the interface, because we may change the interface later
It is recommended to load this class in a method of the class.
The simple code is as follows
import sysfrom PyQt5 import QtWidgets# import this classfrom test import Ui_Form# Create an Application object, the sys.argv parameter is a list of parameters from the command line,app = QtWidgets.QApplication(sys.argv)# Create a widget component base classwindows = QtWidgets.QWidget()# instantiate the class of the ui interfaceui = Ui_Form()# Put the ui interface into the controlui.setupUi(windows)# interface displaywindows.show()# Execute the window trigger event in a loop, and exit without leaving garbage after the end. If you don't add it, the newly created widget component will flash by.sys.exit(app.exec_())
Run like this. This python file will load the interface drawn by qtdesinger.