I have already written a complete code in python but I only run it from the console and it display the results in console. I need help in building a simple UI that has a run button that will allow the code to run and display its results within the user interface window and not on the console. How do I go about this? I am still a python beginner. The already written code is for face detection and recognition.
Asked
Active
Viewed 411 times
1 Answers
1
Example code to run external python script.
import subprocess
import PySimpleGUI as sg
layout = [
[sg.Button("RUN")],
[sg.Output(size=(80, 20))],
]
window = sg.Window("Title", layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event == "RUN":
sp = subprocess.Popen("python myscript.py", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=None)
out, err = sp.communicate()
if out:
print(out.decode("utf-8"))
if err:
print(err.decode("utf-8"))
window.close()

Jason Yang
- 11,284
- 2
- 9
- 23
-
Thanks, this is exactly what I was inquiring about. – Rthirteen Sep 04 '21 at 08:11