I'm making an app where I want to use window and tray at the same time, but the following code needs an event from window first, then it gets the event of the tray, I tried doing both of them separately with threading but no luck there,
Try to do Exit, I mean from tray, and doubleclick tray multiple times, you will see the problem
import PySimpleGUIQt as Sg
for_default = ['a', 'v', 's']
menu_def = ['', ['---', '&p1', ['x', 'y'], '&p2', 'E&xit']]
layout = [[Sg.Text('Default First Second')],
[Sg.Listbox(for_default, enable_events=True, key='-DEFAULT-'),
Sg.Listbox(for_default, enable_events=True, key='-FIRST-'),
Sg.Listbox(for_default, enable_events=True, key='-SECOND-')]]
window = Sg.Window('Window Title', layout, finalize=True)
tray = Sg.SystemTray(menu=menu_def)
tray.ShowMessage('My Message', 'The tray icon is up and runnning!')
while True:
event, values, = window.Read()
menu_item = tray.Read()
if menu_item == 'Exit':
print(event)
print(menu_item)
window.hide()
elif menu_item == Sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED:
window.un_hide()
elif event == '-DEFAULT-':
print(event)