Skip to content Skip to sidebar Skip to footer

Running A Tkinter Window And Pystray Icon Together

I'm building a tkinter gui project and i'm looking for ways to run a tray icon with the tkinter window. I found Pystray library that does it, But now i'm trying to figure it out h

Solution 1:

Finally I figure it out,
Now I just need to combine this with my main code, I hope this code will help to other people too...

from pystray import MenuItem as item
import pystray
from PIL import Image
import tkinter as tk

window = tk.Tk()
window.title("Welcome")

def quit_window(icon, item):
    icon.stop()
    window.destroy()

def show_window(icon, item):
    icon.stop()
    window.after(0,window.deiconify)

def withdraw_window():  
    window.withdraw()
    image = Image.open("image.ico")
    menu = (item('Quit', quit_window), item('Show', show_window))
    icon = pystray.Icon("name", image, "title", menu)
    icon.run()

window.protocol('WM_DELETE_WINDOW', withdraw_window)
window.mainloop()

Post a Comment for "Running A Tkinter Window And Pystray Icon Together"