This example creates a system icon in tray area and exit after 2 seconds. The main function is run in a separate thread.
import threading
import PySimpleGUIQt as sg
def tray_icon():
cnt = 0
menu_def = ["BLANK", ["Exit"]]
tray = sg.SystemTray(menu=menu_def)
while True:
tray.read(100)
cnt += 1
print(cnt)
if cnt > 20:
print('Timeout reached, exiting..')
return
t1 = threading.Thread(target=tray_icon)
t1.start()
t1.join()
print('done')
While the code does the job there seems to be an issue on script termination. This is what it shows in the terminal:
..
..
20
21
Timeout reached, exiting..
done
Segmentation fault (core dumped)
Segmentation fault appears approximately after a minute.
This seems to be specific to Qt port as replacing PySimpleGUI
results in expected behaviour (script exits immediately without any error).