且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用PyQt5设置窗口图标?

更新时间:2023-01-26 23:34:12

答案由问号(隐身图标)给出.我想补充一点,该脚本可能无法在脚本目录中执行.在任何情况下,为了安全起见,您可能需要确保相对于脚本所在的目录加载图标:

The answer has been given by the asker (invisible icon). I wanted to add that the script may not be executed in the script directory. In any case, to be safe, you may want to make sure the icon is loaded relative to the directory in which the script resides:

import os 
# [...]
scriptDir = os.path.dirname(os.path.realpath(__file__))
self.setWindowIcon(QtGui.QIcon(scriptDir + os.path.sep + 'logo.png'))