再代码最后加入
if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) widget = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(widget) widget.show() sys.exit(app.exec_())即可