简体   繁体   中英

Why the output of an external Python Script isn't displaying into my Python Tkinter GUI?

I hope you are doing great this new year, I am creating a GUI program (Python3 Tkinter) which displays the output of another python script into a big entry.

Situation: My GUI has only 1 button which execute this command: python external_python_script.py -h

However I want the whole output of this command execution to be displayed into an entry, and not into the CMD.

So far this is my solution, but not effective:

command_textbox = os.system(python external_python_script.py -h) #simply execute the code in brackets

script_output.insert('1.0',command_textbox) #the whole output of the script will be displayed in this entry

What happened when I did this?

In the GUI program, when I pressed the button, into the Entry it is displayed only this 0

Any help is greatly appreciated, thank you!

Thank you guys for helping me, Subprocess is the solution. So I put only these 2 lines of code and I got the solution I wanted:

final_command = subprocess.run(command, capture_output=True)

output_box.insert('1.0',final_command)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM