moses-palmer / pystray

GNU General Public License v3.0
472 stars 59 forks source link

Click on system icon tary open app #141

Closed omides248 closed 1 year ago

omides248 commented 1 year ago
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("lib//assets//icon.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()

How to open the app automatically by clicking (left click mouse) on the system icon tray?

Now I have to display app it by right clicking and clicking the show option. I want it to appear with the left click on the quick-up icon. Thankful

Untitled
moses-palmer commented 1 year ago

Thank you for you report.

Depending on the platform on which your application run, this is possible by setting the default argument to True for your default menu item. Please consult the documentation.