Solution to the problem that the. Py file generated by the. UI file does not appear in the interface

Time:2019-10-19

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.


sys.exit(app.exec_()) 

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.

Recommended Today

Single and multiple buttons are styled with pictures

I’ve always seen people asking how to style and enlarge the buttons of radio buttons and multi buttons? Let’s share an example I did. 1. First make the button into a picture  2.html page Copy code The code is as follows: <!DOCTYPE HTML> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <script type=”text/javascript” src=”jquery-1.10.2.min.js”></script> <script type=”text/javascript”> […]