()
| 40 | # dP dP dP `88888P8 dP dP dP |
| 41 | |
| 42 | def main(): |
| 43 | |
| 44 | layout = [ |
| 45 | [sg.Text('00:00:00', font=('Courier New', 20, 'bold'), justification='center', expand_x=True, key='-TIME-')], |
| 46 | [sg.Push(), sg.Button('Start'), sg.Button('Stop')]] |
| 47 | |
| 48 | window = sg.Window('Threading', layout, enable_close_attempted_event=True, |
| 49 | print_event_values=True, # enable to watch the events and values print out |
| 50 | ) |
| 51 | |
| 52 | window.job_running = False # Create a member variable to signal to the thread when to stop |
| 53 | exiting = False # Used when X is clicked |
| 54 | |
| 55 | while True: |
| 56 | |
| 57 | event, values = window.read() |
| 58 | |
| 59 | if event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT: |
| 60 | if window.job_running: # if thread running, tell it to exit |
| 61 | window.job_running = False |
| 62 | exiting = True |
| 63 | else: |
| 64 | break # if thread not running then OK to exit |
| 65 | |
| 66 | if exiting and event == '-THREAD ENDED-': # If exiting and thread is finished then OK to exit |
| 67 | break |
| 68 | |
| 69 | elif event == 'Start': |
| 70 | window['Start'].update(disabled=True) |
| 71 | window.job_running = True |
| 72 | window.start_thread(lambda: the_thread(window), '-THREAD ENDED-') |
| 73 | |
| 74 | elif event == 'Stop': |
| 75 | window.job_running = False |
| 76 | window['Start'].update(disabled=False) |
| 77 | |
| 78 | elif event == '-THREAD-' and values[event] != window['-TIME-'].get(): |
| 79 | window['-TIME-'].update(values[event]) |
| 80 | |
| 81 | window.close() |
| 82 | |
| 83 | if __name__ == '__main__': |
| 84 | main() |
no test coverage detected