0
私は2つのpythonファイルを持っています。 1つはhelloworld.py、2つ目はmain.pyです。 main.pyにはbuttonがあります。そのボタンをクリックすると、helloworld.pyの結果をテキストボックスに出力します。Python tkinter GUIでCLI結果を表示
helloworld.py
印刷( "こんにちは世界")
ので、私が代わりにos.system
の使用subprocess.check_output
main.pyテキストボックスにハロー
from tkinter import *
import os
root= Tk()
root.title("My First GUI")
root.geometry("800x200")
frame1=Frame(root)
frame1.grid()
def helloCallBack():
result = os.system('python helloworld.py')
if result==0:
print("OK")
text1.insert(END,result)
else:
print("File Not Found")
label1 = Label(frame1, text = "Here is a label!")
label1.grid()
button1 = Button(frame1,text="Click Here" , foreground="blue",command= helloCallBack)
button1.grid()
text1 = Text(frame1, width = 35, height = 5,borderwidth=2)
text1.grid()
radiobutton1 = Radiobutton(frame1, text= "C Programming", value=0)
radiobutton1.grid()
radiobutton2 =Radiobutton(frame1, text= "Python Programming")
radiobutton2.grid()
root.mainloop()
ありがとうございました。しかし、今私は全出力をすぐに得ています。私が望むのは、GUIがターミナルに印刷するのと同じように、出力を繰り返し印刷する必要があるということです。 –
私はあなたが繰り返し何を意味するのか分かりません。単に「こんにちは世界」を印刷するよりも複雑なことを考えると思います。あなたは私に例を教えていただけますか? –
私はそれを介してFlashairから画像を取得するflash.pyのpythonファイルを持っています。ループを反復したい場合 –