Search code examples
pythonpython-3.xpyqtpyqt5qsystemtrayicon

why icon of QSystemTrayIcon not hide in my system?


I wrote a program that create a tray. I want to hide it with below code,but it not work(tray icon is visible). how solve this problem?

from PyQt5 import QtGui, QtWidgets

if __name__ == '__main__':
   app = QtWidgets.QApplication([])
   sysTray =QtWidgets.QSystemTrayIcon()
   sysTray.setIcon(QtGui.QIcon('1.jpg'))
   sysTray.hide()
   app.exec_()

Solution

  • Just add sysTray.show() before sysTray.hide()