首先證明我是加了那些鬼東西以后可以成功運行的。
然后來敘述一下我的過程。
這是一個.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 *
最后終端運行。
眾生踩坑皆苦