Starts and executes the GUI Reads data from a Queue and displays the data to the window Returns when the user exits / closes the window
()
| 37 | |
| 38 | |
| 39 | def the_gui(): |
| 40 | """ |
| 41 | Starts and executes the GUI |
| 42 | Reads data from a Queue and displays the data to the window |
| 43 | Returns when the user exits / closes the window |
| 44 | """ |
| 45 | sg.theme('Light Brown 3') |
| 46 | |
| 47 | layout = [[sg.Text('Long task to perform example')], |
| 48 | [sg.Output(size=(70, 12))], |
| 49 | [sg.Text('Number of seconds your task will take'), |
| 50 | sg.Input(default_text=5, key='-SECONDS-', size=(5, 1)), |
| 51 | sg.Button('Do Long Task', bind_return_key=True)], |
| 52 | [sg.Button('Click Me'), sg.Button('Exit')], ] |
| 53 | |
| 54 | window = sg.Window('Multithreaded Window', layout) |
| 55 | |
| 56 | # --------------------- EVENT LOOP --------------------- |
| 57 | while True: |
| 58 | event, values = window.read() |
| 59 | if event in (sg.WIN_CLOSED, 'Exit'): |
| 60 | break |
| 61 | elif event == 'Do Long Task': |
| 62 | seconds = int(values['-SECONDS-']) |
| 63 | print('Thread ALIVE! Long work....sending value of {} seconds'.format(seconds)) |
| 64 | window.start_thread(lambda: long_operation_thread(seconds, window), ('-THREAD-', '-THEAD ENDED-')) |
| 65 | elif event == 'Click Me': |
| 66 | print('Your GUI is alive and well') |
| 67 | elif event[0] == '-THREAD-': |
| 68 | print('Got a message back from the thread: ', event[1]) |
| 69 | |
| 70 | # if user exits the window, then close the window and exit the GUI func |
| 71 | window.close() |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | the_gui() |
no test coverage detected