PyQt5系统托盘

from PyQt5.QtWidgets import QDialog, QAction, QSystemTray, QMenu
from PyQt5.QtGui import QIcon

class DlgMain(QDialog):
    def addSystemTray(self):
        minimizeAction = QAction("Mi&nimize", self, triggered=self.hide)
        maximizeAction = QAction("Ma&ximize", self,
           triggered=self.showMaximized)
        restoreAction = QAction("&Restore", self,
           triggered=self.showNormal)
        quitAction = QAction("&Quit", self,
           triggered=self.close)
        self.trayIconMenu = QMenu(self)
        self.trayIconMenu.addAction(minimizeAction)
        self.trayIconMenu.addAction(maximizeAction)
        self.trayIconMenu.addAction(restoreAction)
        self.trayIconMenu.addSeparator()
        self.trayIconMenu.addAction(quitAction)
        self.trayIcon = QSystemTrayIcon(self)
        self.trayIcon.setIcon(QIcon("skin/icons/logo.png"))
        self.setWindowIcon(QIcon("skin/icons/logo.png"))
        self.trayIcon.setContextMenu(self.trayIconMenu)
        self.trayIcon.show()
        #sys.exit(self.exec_())

    def closeEvent(self, event):
        if self.trayIcon.isVisible():
            self.trayIcon.hide()

效果:

这里写图片描述

你可能感兴趣的:(PyQt5,PyQt5的学习工作总结)