示例代码
代码语言:python
代码运行次数:0
复制from __future__ import annotations
import sys
from random import randint
from PySide6.QtCore import Slot
from PySide6.QtGui import QAction, QIcon
from PySide6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
@Slot()
def demo_tray_action():
print('demo tray action', randint(999, 99999))
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
tray = QSystemTrayIcon()
tray.setIcon(QIcon('/xxxxxx/ubuntu-plain-icon.svg'))
tray.setVisible(True)
tray.setToolTip('a tray app with ubuntu icon')
menu = QMenu()
action = QAction('DemoTrayAction')
action.triggered.connect(demo_tray_action)
menu.addAction(action)
tray_quit = QAction('TrayAppQuit')
tray_quit.triggered.connect(app.quit)
menu.addAction(tray_quit)
tray.setContextMenu(menu)
app.exec()
运行效果