Open NewbieXvwu opened 2 years ago
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 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 Thanks!
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