0
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: The three system tray icons 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.

InfiniteFox
  • 81
  • 1
  • 2
  • I would recommend not running as a process but rather just as the main thread. Or maybe if you do, move the creation of the SystemTray object into your function. When you fork to stat the process, it's going to create the object every time you fork the process. – Mike from PSG Jun 17 '20 at 14:46
  • There is a demo program that runs on all of the PySimpleGUI ports that does what you're after (a notification every X minutes) https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_System_Tray_Reminder.py – Mike from PSG Jun 17 '20 at 14:48

0 Answers0