ttkbootstrap icon indicating copy to clipboard operation
ttkbootstrap copied to clipboard

Hide program to system tray

Open NewbieXvwu opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe.

It's just a new feature,and it's not related to any problems.If it's hard to achieve, it doesn't matter.

Describe the solution you'd like

I want to hide my program to system tray.

Describe alternatives you've considered

Emm...I have searched the Internet,but it seems that there are no solutions now.

Additional context

NewbieXvwu avatar Feb 27 '22 11:02 NewbieXvwu

There is a solution,but it needs pywin32,and it's made by Python 2. In addition, this is a Chinese website. You may need Google translation. https://segmentfault.com/q/1010000008579491

NewbieXvwu avatar Feb 27 '22 11:02 NewbieXvwu

@NewbieXvwu You don't really need pywin32. You need pystray... and some threading🤔

pip install pystray

Here is simple solution, you might try limit amount of threads running on this function with ThreadPoolExecutor

from pystray import Icon, Menu, MenuItem
from threading import Thread
from PIL import Image
...
def run_tray():
    icon = Image.open('path\to\icon')
    menu = Menu(MenuItem('Show', show_function), MenuItem('Quit', quit_function))
    Icon('Name of tray', icon, 'Title of tray', menu).run()

Thread(target=run_tray).start()
root.mainloop()

Or you could just simply use .run_detached()

from pystray import Icon, Menu, MenuItem
from PIL import Image
...
def run_tray():
    icon = Image.open('path\to\icon')
    menu = Menu(MenuItem('Show', show_function), MenuItem('Quit', quit_function))
    Icon('Name of tray', icon, 'Title of tray', menu).run_detached()
root.mainloop()

Zeusek avatar Jul 22 '22 23:07 Zeusek

@Zeusek Thanks!

NewbieXvwu avatar Jul 23 '22 11:07 NewbieXvwu