'PySimpleGUI code to run specific RunCell in the code?

that is my first question here so if I missed any rule let me know. I am also very beginner in coding so my approach might not be efficient in some cases.

I wrote a Python code (using Visual Studio Code) to automate one of my main work process. The whole code I divided with #%% on parts. So I run each cell one by one, because after each cell I do manual quality checks. So the code looks like:

#%%
code part 1
#base on output i do checks and decision if I can move forward with code

#%%
code part 2
#base on output i do checks and decision if I can move forward with code

#%%
code part ...

#%%
code part 9

end

Now, I would like to add GUI with which I will control which part of the code should be run and output of that portion will be presented to me within the output window.

I`m missing knowledge how to refer button in my GUI code to run specific RunCell in the code?

I`m using PySimpleGUI and so far code looks like:

import PySimpleGUI as sg      

layout = [[sg.Text('Persistent window')],      
          [sg.InputText(key='_OUTPUT_')],      
          [sg.Button('RunCell_1'), sg.Exit()],
          [sg.Button('RunCell_2')]]      

window = sg.Window('Window that stays open', layout)      

while True:
    event, values = window.read() 
    print(event, values)       
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'RunCell_1' #what now, how specify which part to run?
        if out: window['_OUTPUT_'].update(values['values from main code'])

window.close()


Sources

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

Source: Stack Overflow

Solution Source