簡體   English   中英

為什么外部 Python 腳本的輸出沒有顯示在我的 Python Tkinter GUI 中?

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

我希望你在新的一年里做得很好,我正在創建一個 GUI 程序(Python3 Tkinter),它將另一個 python 腳本的輸出顯示到一個大條目中。

情況:我的 GUI 只有 1 個執行此命令的按鈕: python external_python_script.py -h

但是,我希望將此命令執行的整個輸出顯示在一個條目中,而不是顯示在 CMD 中。

到目前為止,這是我的解決方案,但無效:

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

當我這樣做時發生了什么?

在 GUI 程序中,當我按下按鈕時,進入條目它只顯示這個0

非常感謝任何幫助,謝謝!

謝謝你們幫助我,Subprocess 是解決方案。 所以我只放了這兩行代碼,就得到了我想要的解決方案:

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

output_box.insert('1.0',final_command)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM