'PySimpleGUI how to run a perform_long_operation function that returns a value

just started learning and using PySimpleGUI. So far, everything works. I have a method that trains an AI and returns the model:

model = train_model()

As this method takes a while, I use the window.perform_long_operation(lambda: train_model(), "modelTrained") function

However, I can not find a way to run it and return a value. I have tried this:

model = window.perform_long_operation(lambda: train_model(), "modelTrained")

and this:

window.perform_long_operation(lambda: model = train_model(), "modelTrained")

Is there a way to run a method via perform_long_operation() that also returns a value?



Solution 1:[1]

You'll find the Cookbook explains the steps to use this method as well as how to get your return value: https://pysimplegui.readthedocs.io/en/latest/cookbook/#pysimplegui-windowperform_long_operation

The docstring for the method also has the same information. You can see the docstring in your IDE, through the built-in SDK reference, and in the call reference in the documentation http://Calls.PySimpleGUI.org

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike from PSG