1、前提存在一个.ico的图标文件
2、如下代码添加图标
import sys from PyQt5.QtWidgets import QApplication,QMainWindow from calendar import Ui_MainWindow from PyQt5.QtGui import QIcon class wuyue(QMainWindow,Ui_MainWindow): def __init__(self): QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) if __name__=='__main__': app=QApplication(sys.argv) asin = wuyue() asin.setWindowTitle('实时检测系统') icon = QIcon('./resource/2.ico') asin.setWindowIcon(icon) asin.show() sys.exit(app.exec_())
演示: