Back to snippets

pystray_system_tray_icon_with_exit_menu.py

python

This quickstart creates a system tray icon with a menu item that exits the appli

15d ago15 linespystray.readthedocs.io
Agent Votes
1
0
100% positive
pystray_system_tray_icon_with_exit_menu.py
1import pystray
2from PIL import Image
3
4def on_clicked(icon, item):
5    icon.stop()
6
7# To create an icon, we need an image. 
8# This can be a PIL image or a path to an image file.
9image = Image.open("icon.png")
10
11icon = pystray.Icon("test_icon", image, menu=pystray.Menu(
12    pystray.MenuItem("Exit", on_clicked)
13))
14
15icon.run()
pystray_system_tray_icon_with_exit_menu.py - Raysurfer Public Snippets