import win10toast
import time
import PySimpleGUIQt as sg
from multiprocessing import Process
menu_def = ['BLANK', ['&About', 'E&xit']]
tray = sg.SystemTray(menu=menu_def, filename=r'icon.ico')
def SysTray():
while True:
menu_item = tray.Read()
print(menu_item)
if menu_item == 'Exit':
break
elif menu_item == 'About':
sg.Popup('Test Title', 'Test Message.')
def Main():
while True:
toaster = win10toast.ToastNotifier()
toaster.show_toast('Test Title', 'Test Message.', duration=10)
time.sleep(3590)
if __name__ == '__main__':
Process(target=SysTray).start()
Process(target=Main).start()
My intention with this code is to have a program that sends the user a message every hour and can be exited via the system tray. While this code does indeed work, it will display not one system tray icon but three with only one of them working properly.
This is what it looks like in action:
As you can see, the system tray icon is displayed three times and only one of them shows a menu when you right click it.
I have already tried running the two loops with the threading module instead
thread1 = Thread(target = SysTray)
thread2 = Thread(target = Main)
thread1.run()
thread2.run()
But that lead to the System tray icon just being displayed with not functionality.
Thanks in advance. I'm really losing my mind over this.