如何实例化QSystemTrayIcon?

时间:2017-02-17 07:35:41

标签: python pyqt qt5

如何解决以下错误?

from PyQt5 import Qt
import sys
app = Qt.QApplication(sys.argv)
systemtray_icon = Qt.QSystemTrayIcon(app,    
Qt.QIcon(r'C:\Users\psivabal\Desktop\o-SWAMI-VIVEKANANDA-facebook.jpg'))
systemtray_icon.show()
systemtray_icon.showMessage('Title', 'Content')

错误:

Traceback (most recent call last):
  File "C:/Users/psivabal/Desktop/Udacity/My_Examples/Cricket Score trying/TRial.py", line 4, in <module>
    systemtray_icon = Qt.QSystemTrayIcon(app, Qt.QIcon(r'C:\Users\psivabal\Desktop\o-SWAMI-VIVEKANANDA-facebook.jpg'))
TypeError: arguments did not match any overloaded call:
  QSystemTrayIcon(parent: QObject = None): too many arguments
  QSystemTrayIcon(QIcon, parent: QObject = None): argument 1 has unexpected type 'QApplication'

1 个答案:

答案 0 :(得分:0)

根据the documentation,你应该如下实例化QSystemTrayIcon:

Qt.QSystemTrayIcon(Qt.QIcon(r'icon.jpg'), app)

提示:QObject来自AFTER图标实例