首先证明我是加了那些鬼东西以后可以成功运行的。
然后来叙述一下我的过程。
这是一个.ui文件生成的.py文件。(把主要的内容省去了,但是没有影响结构)
1 # -*- coding: utf-8 -*- 2 3 # Form implementation generated from reading ui file 'wallet_content.ui' 4 # 5 # Created by: PyQt5 UI code generator 5.10.1 6 # 7 # WARNING! All changes made in this file will be lost! 8 9 from PyQt5 import QtCore, QtGui, QtWidgets 10 11 class Ui_wallet_content(object): 12 def setupUi(self, wallet_content): 13 wallet_content.setObjectName("wallet_content") 14 #以下省略137 138 def retranslateUi(self, wallet_content): 139 #以下省略
可见object name为wallet_content(13行)
wallet_content.setObjectName("wallet_content")
在setupUi函数最后加 :object name.show()

然后在py文件末尾加
1 if __name__ == "__main__": 2 app = QApplication(sys.argv) 3 form = QWidget() 4 w = Ui_wallet_content() //Ui_类名(),因为自动生成的类名为Ui_objectname() 5 w.setupUi(form) 6 form.show() 7 sys.exit(app.exec_())
最后加上头文件
我一般都是暴力加
1 import sys, os 2 from PyQt5 import QtCore, QtWidgets, QtGui 3 from PyQt5.QtCore import * 4 from PyQt5.QtWidgets import * 5 from PyQt5.QtGui import *
最后终端运行。
众生踩坑皆苦