Generally, the following two packages need to be imported
from PyQt5.QtWidgets import QApplication import sys
And add the following code to the. Py file:
if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) widget = QtWidgets.QWidget() ui = Ui_MainWindow() ui.setupUi(widget) widget.show() sys.exit(app.exec_())
The individual codes above are explained below
widget = QtWidgets.QWidget()
Because the default object class inherited by QT designer does not provide the show() display method, we generate a QWidget object to overload the UI MainWindow class designed by us to achieve the display effect.
App. Exec ± () — run app sys. Exit (app. Exec ± ()) — return 0 after the message loop, and then call sys. Exit (0) to exit the program.
The above solution to the problem that the. Py file generated by the. UI file does not appear in the interface is all the content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developer more.