我已经阅读了这个问题的许多解决方案,但我仍然无法使这个简单的程序工作。我知道这可能真的很简单,但我不知道我错过了什么。
我有这个简单的程序:
from Tkinter import *
import subprocess
def run():
process=subprocess.Popen(some_script, shell=True, stdout=subprocess.PIPE)
while True:
nextline = process.stdout.readline()
if not nextline:
break
output.set(nextline)
root.update_idletasks()
root = Tk()
output = StringVar()
label1 = Label(root, textvariable=output)
label1.pack()
button1 = Button(root, text="Go", command=run)
button1.pack()
root.mainloop()
所以当我点击按钮时, some_script 被执行。我希望标签定期更新脚本的输出,但它没有。我究竟做错了什么?