在PyQt5应用程序的任务栏中设置与应用程序图标相同的图标

3
我在为pyqt5应用程序的任务栏管理器附加相同图标时遇到了麻烦,就像我为pyqt5应用程序的图标所做的那样。我已经附上了下面的代码以在pyqt5中显示图标,只需要一点帮助来编写用于在任务栏中显示应用程序相同图标的代码。 enter image description here enter image description here
import sys
from SplashScreen import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QColor, qGray, QImage, QPainter, QPalette,QIcon
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtWidgets import QApplication, QWidget
if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('./cricket.png'))
    w = QWidget()
    w.resize(300,300)
    w.setWindowTitle('Quick Cricket')
    w.show()
    sys.exit(app.exec_())

提前感谢


请将代码以文本形式发布,而非图像。然后,请确保您提供了一个最小可复现示例 - musicamante
import sys from SplashScreen import * from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QColor, qGray, QImage, QPainter, QPalette,QIcon from PyQt5.QtCore import Qt, QUrl from PyQt5.QtWidgets import QApplication, QWidget if __name__ == "__main__": app = QApplication(sys.argv) app.setWindowIcon(QIcon('./cricket.png')) w = QWidget() w.resize(300,300) w.setWindowTitle('Quick Cricket') w.show() sys.exit(app.exec_()) - Abdul Rehman
这是示例代码。 - Abdul Rehman
不要使用注释,因为它们不支持格式化,并且使代码变得难以阅读。请编辑问题并遵循有关格式化代码的指南。 - musicamante
@musicamante 仍在等待答案。 - Abdul Rehman
我只是指出了你问题中的问题,并不意味着我知道答案。请避免不必要的注释,并且要有耐心,这不是一个论坛或聊天室,绝对不是一场比赛:有时候答案会在提问后数年才给出。 - musicamante
2个回答

5

猜猜我找到了答案。

我在应用程序开头使用了三行代码,然后运行代码,窗口显示与我的标志相同的图标。

import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

这些代码的作用是什么?简而言之,这些代码将告诉窗口,这是我自己注册的应用程序,所以我将决定它的图标。
我要感谢@DamonJW Stack Overflow开发者。感谢@DamonJW。 这是解决方案的链接。

< https://dev59.com/w3I_5IYBdhLWcg3wDOdC#1552105


请将链接作为实际链接发布,并阅读markdown帮助 - musicamante

0

enter image description here

解决方案在这一行

import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

请考虑在源代码中添加一些解释,说明它是如何解决问题的。 - Azhar Khan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接