对应路径上要有web.ico图标哈
代码:
import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMainWindow
class IconForm(QMainWindow):
def __init__(self):
super(IconForm, self).__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300,300,250,250)
# 设置窗口标题
self.setWindowTitle('设置窗体图标')
# 设置窗口图标
self.setWindowIcon(QIcon('../web.ico'))
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
# app.setWindowIcon(QIcon('../web.ico'))
w = IconForm()
w.show()
sys.exit(app.exec_())