Criação de icone para o “system tray” em Python usando PyQT

Instalar o pyqt5:

pip install pyqt5

Exemplo:

from PyQt5 import QtGui, QtWidgets
import sys
 
class SystemTrayApp(QtWidgets.QSystemTrayIcon):
    def __init__(self, icon, parent=None):
        super().__init__(icon, parent)
        # Set up the menu
        self.menu = QtWidgets.QMenu(parent)
        
        # Add actions to the menu
        open_action = self.menu.addAction("Open")
        exit_action = self.menu.addAction("Exit")
        
        # Connect the actions to functions
        open_action.triggered.connect(self.open)
        exit_action.triggered.connect(self.exit)
        
        # Set the menu to the system tray icon
        self.setContextMenu(self.menu)
        self.setToolTip("System Tray Example")
        self.activated.connect(self.on_click)
 
    def open(self):
        QtWidgets.QMessageBox.information(None, "Info", "Open clicked!")
    
    def exit(self):
        QtWidgets.QApplication.quit()
    
    def on_click(self, reason):
        if reason == QtWidgets.QSystemTrayIcon.Trigger:
            QtWidgets.QMessageBox.information(None, "Info", "Tray Icon clicked!")
 
def main():
    app = QtWidgets.QApplication(sys.argv)
    
    # Create an icon
    icon = QtGui.QIcon("path/to/icon.png")  # Replace with your icon file path
    
    # Create the system tray app
    tray = SystemTrayApp(icon)
    tray.show()
    
    # Run the application loop
    sys.exit(app.exec_())
 
if __name__ == '__main__':
    main()