1, provided that there is a file icon in .ico
2, the following code to add an icon
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 ( ' real-time detection system ' ) icon = QIcon ( ' ./resource/2.ico ' ) asin.setWindowIcon (icon) asin.show () the sys.exit (app.exec_ ())
Demo: