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

Function main

DemoPrograms/Demo_Long_Operations.py:83–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81# This is your new code that uses a thread to perform the long operation
82
83def main():
84 layout = [ [sg.Text('Indirect Call Version')],
85 [sg.Text('How many times to run the loop?'), sg.Input(s=(4,1), key='-IN-')],
86 [sg.Text(s=(30,1), k='-STATUS-')],
87 [sg.Button('Go', bind_return_key=True), sg.Button('Exit')] ]
88
89 window = sg.Window('Window Title', layout)
90
91 while True: # Event Loop
92 event, values = window.read()
93 print(event, values)
94 if event == sg.WIN_CLOSED or event == 'Exit':
95 break
96 elif event == 'Go':
97 window['-STATUS-'].update('Calling your function...')
98 if values['-IN-'].isnumeric():
99
100 # This is where the magic happens. Add your function call as a lambda
101 window.perform_long_operation(lambda :
102 my_long_func(int(values['-IN-']), a=10),
103 '-END KEY-')
104 else:
105 window['-STATUS-'].update('Try again... how about an int?')
106 elif event == '-END KEY-':
107 return_value = values[event]
108 window['-STATUS-'].update(f'Completed. Returned: {return_value}')
109 window.close()
110
111
112'''

Callers 1

Calls 4

readMethod · 0.95
closeMethod · 0.95
my_long_funcFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected