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

Function main

DemoPrograms/Demo_Multithreaded_Calling_Popup.py:41–67  ·  view source on GitHub ↗

Every time "Start A Thread" is clicked a new thread is started When the event is received from the thread, a popup is shown in its behalf

()

Source from the content-addressed store, hash-verified

39
40
41def main():
42 """
43 Every time "Start A Thread" is clicked a new thread is started
44 When the event is received from the thread, a popup is shown in its behalf
45 """
46
47 layout = [ [sg.Output(size=(60,10))],
48 [sg.T('How often a thread will show a popup in seconds'),
49 sg.Spin((2, 5, 10, 20), initial_value=5, k='-SPIN-')],
50 [sg.B('Start A Thread'), sg.B('Dummy'), sg.Button('Exit')] ]
51
52 window = sg.Window('Window Title', layout, finalize=True, font='_ 15')
53
54
55 while True: # Event Loop
56 event, values = window.read()
57 print(event, values)
58 if event == sg.WIN_CLOSED or event == 'Exit':
59 break
60 if event == '-POPUP-':
61 sg.popup_non_blocking('This is a popup that the thread wants to show',
62 *values['-POPUP-'])
63 elif event == 'Start A Thread':
64 print(f'Starting thread. You will see a new popup every {values["-SPIN-"]} seconds')
65 threading.Thread(target=the_thread, args=(window, values['-SPIN-']), daemon=True).start()
66
67 window.close()
68
69
70if __name__ == '__main__':

Calls 3

readMethod · 0.95
closeMethod · 0.95
startMethod · 0.80

Tested by

no test coverage detected