MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_System_Tray_GUI_Window_Design_Pattern.py:46–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 return sg.Window('Window Title', layout, element_justification='c', icon=icon)
45
46def main():
47
48 menu_def = ['UNUSED', ['Show','Hide','Exit']]
49
50 tray = sg.SystemTray(menu=menu_def, data_base64=icon)
51 window = make_a_window()
52 start, current, paused = time_as_int(), 0, True
53
54 while True:
55 event = tray.read(timeout=100)
56 if event == 'Exit':
57 break
58 elif event in('Show', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED) and not window:
59 print('Showing a new window')
60 window, paused = make_a_window(), True
61 elif event == 'Hide' and window:
62 window.close()
63 window = None
64
65 if window:
66 event, values = window.read(timeout=1000)
67 if event in (sg.WIN_CLOSED, 'Minimize\nTo Tray'):
68 print('Minimizing to tray')
69 tray.show_message('Minimizing', 'Minimizing to Tray')
70 window.close()
71 window = None
72 continue
73 elif event == 'Start':
74 start, paused = time_as_int(), False
75 if not paused:
76 remaining = delay_time - (time_as_int() - start)
77 if remaining < 0:
78 tray.show_message('Look away', 'It is time to look away for 20 seconds')
79 start = time_as_int()
80 else:
81 window['-OUT-'].update(f'{remaining//60%60:2}:{remaining%60:02}')
82 tray.close()
83 if window:
84 window.close()
85
86
87main()

Calls 8

readMethod · 0.95
show_messageMethod · 0.95
closeMethod · 0.95
make_a_windowFunction · 0.85
time_as_intFunction · 0.70
closeMethod · 0.45
readMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected