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

Function main

DemoPrograms/Demo_Timer_Periodic.py:81–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79
80
81def main():
82 layout = [[sg.Text('Window with periodic time events')],
83 [sg.Text(key='-MESSAGE-')],
84 [sg.Text('Timer Status:'), sg.Text(key='-TIMER STATUS-')],
85 [sg.Text('Duration:'), sg.In(s=3, key='-DURATION-'), sg.Button('Start')],
86 [sg.Text('Timer ID:'), sg.In(s=3, key='-STOP ID-'), sg.Button('Stop'),],
87 [ sg.Button('Dummy'), sg.Button('Exit')], ]
88
89 window = sg.Window('Blinking LED Window', layout)
90
91 timer_counter = 0
92 # --------------------- EVENT LOOP ---------------------
93 while True:
94 event, values = window.read()
95 if event in (sg.WIN_CLOSED, 'Exit'):
96 break
97 window['-MESSAGE-'].update(f'{event} {values}')
98 window['-TIMER STATUS-'].update(f'{timer_running}')
99 if event == 'Start':
100 if values['-DURATION-']:
101 timer_status_change(timer_counter, start=True)
102 window.start_thread(lambda: periodic_timer_thread(window, float(values['-DURATION-']), timer_counter), ('-THREAD-', '-THREAD ENDED-'))
103 timer_counter += 1
104 else:
105 window['-MESSAGE-'].update('Please enter a numeric duration')
106 elif event == 'Stop':
107 if values['-STOP ID-']:
108 timer_status_change(int(values['-STOP ID-']), stop=True)
109
110 window.close()
111
112if __name__ == '__main__':
113 main()

Callers 1

Calls 6

readMethod · 0.95
start_threadMethod · 0.95
closeMethod · 0.95
timer_status_changeFunction · 0.85
periodic_timer_threadFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected