Python 从资源中引用时,不会显示窗口和系统托盘图标
这是testTray.pyPython 从资源中引用时,不会显示窗口和系统托盘图标,python,resources,python-3.x,pyqt,Python,Resources,Python 3.x,Pyqt,这是testTray.py from PyQt4.QtCore import * from PyQt4.QtGui import * import imgAgent_rc class Window(QDialog): def __init__(self): super(Window, self).__init__() self.trayIcon = QSystemTrayIcon(self) icon = QIcon(':/imag
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import imgAgent_rc
class Window(QDialog):
def __init__(self):
super(Window, self).__init__()
self.trayIcon = QSystemTrayIcon(self)
icon = QIcon(':/images/logo/image_16x16.png') # Problem
#icon = QIcon('images/logo/image_16x16.png') # OK
self.trayIcon.setIcon(icon)
self.trayIcon.setVisible(True)
self.trayIcon.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
这是目录结构:
imgAgent.qrc
imgAgent_rc.py
testTray.py
+images
|---+logo
|---image_16x16.png
中华人民共和国
<RCC>
<qresource prefix="logo">
<file>images/logo/image_16x16.png</file>
...
</qresource>
</RCC>
图像/徽标/图像_16x16.png
...
我使用生成了.py资源文件:pyrcc4.exe-py3-o imgAgent\u rc.py imgAgent.qrc
从资源引用时,系统托盘图标和窗口图标不会显示,但在相对路径引用时,系统托盘图标和窗口图标会正常显示。
尝试使用此资源文件代码:
<RCC>
<qresource>
<file>images/logo/image_16x16.png</file>
</qresource>
</RCC>
图像/徽标/图像_16x16.png
你能发布imgAgent.qrc吗,因为我认为你在qrc文件中为图标设置的路径与/images/logo/image16x16.png不同。是的,对不起,我忘了最重要的一件事。我发了邮件,我忘了发.qrc文件。图像就在那里,你说得对。我不小心使用了prefix=“logo”。我试过icon=QIcon(':/logo/images/logo/image_16x16.png')并成功了。我的错误,在我眼前:-P