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

Function main

DemoPrograms/Demo_Multithreaded_popup.py:54–82  ·  view source on GitHub ↗

The demo will display in the multiline info about the event and values dictionary as it is being returned from window.read() Every time "Start" is clicked a new thread is started Try clicking "Dummy" to see that the window is active while the thread stuff is happening in the backgro

()

Source from the content-addressed store, hash-verified

52
53
54def main():
55 """
56 The demo will display in the multiline info about the event and values dictionary as it is being
57 returned from window.read()
58 Every time "Start" is clicked a new thread is started
59 Try clicking "Dummy" to see that the window is active while the thread stuff is happening in the background
60 """
61 global mainthread_queue
62
63 mainthread_queue = queue.Queue()
64
65 layout = [ [sg.Text('Output Area - cprint\'s route to here', font='Any 15')],
66 [sg.Multiline(size=(65,20), key='-ML-', autoscroll=True, reroute_stdout=True, write_only=True, reroute_cprint=True)],
67 [sg.T('Input so you can see data in your dictionary')],
68 [sg.Input(key='-IN-', size=(30,1))],
69 [sg.B('Start A Thread'), sg.B('Dummy'), sg.Button('Exit')] ]
70
71 window = sg.Window('Window Title', layout, finalize=True, keep_on_top=True)
72 count = 0
73 while True: # Event Loop
74 event, values = window.read(timeout=500)
75 sg.cprint(event, values) if event != sg.TIMEOUT_EVENT else None
76 if event == sg.WIN_CLOSED or event == 'Exit':
77 break
78 process_popup()
79 if event.startswith('Start'):
80 threading.Thread(target=the_thread, args=(count,), daemon=True).start()
81 count += 1
82 window.close()
83
84
85if __name__ == '__main__':

Callers 1

Calls 4

readMethod · 0.95
closeMethod · 0.95
process_popupFunction · 0.85
startMethod · 0.80

Tested by

no test coverage detected