1 year ago

#230907

test-img

Azure

How to keep system tray icon with tkinter

I'm trying to create a code for a fan controller and I already got to the point of creating a system tray icon when closed, but when you click the icon to show the app and close again, the system tray icon no longer appears, can someone help me? Here's the part of the code responsible for the system tray icon:

from pystray import MenuItem as item
import pystray
from PIL import Image, ImageTk

def quit_window(icon, item):
    icon.stop()
    root.destroy()
def show_window(icon, item):
    icon.stop()
    root.after(0,root.deiconify())
def hide_window():
    root.withdraw()
    image=Image.open("../Resources/icon.png")
    menu=(item('Quit', quit_window), item('Show', show_window))
    icon=pystray.Icon("name", image, "My System Tray Icon", menu)
    icon.run()

    root = tk.Tk()
    img = tk.Image("photo", file='../Resources/icon.png')
    root.protocol('WM_DELETE_WINDOW', hide_window)

python

tkinter

tk-toolkit

system-tray

0 Answers

Your Answer

Accepted video resources