【发布时间】:2021-03-06 15:14:56
【问题描述】:
我的 tkinter GUI (python 2.7) 启动了一个可以运行很长时间的子进程,我使用 PIPE 将打印语句发送到文本小部件。它可以在没有任何打印语句的情况下运行很长时间,并且 GUI 窗口显示“无响应”,而我在该窗口中无能为力。
#lauch main
proc = subprocess.Popen(["python", testPath, filePath] + script_list,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0)
#send the scripts output to the GUI text box
for line in iter(proc.stdout.readline,''):
text.insert(END, line)
#update in "real time"
text.see(END)
root.update()
text.update_idletasks()
尝试在子进程中添加 print 和 flush 语句,但这没有帮助。
【问题讨论】:
-
读过那篇文章,但不知道它对我有什么帮助。谢谢!
-
尝试使用
threading -
需要进一步阅读。这是 subprocess.Popen 的替代品吗?
-
您不能在 tkinter 应用程序中执行阻止
mainloop()运行的操作,因此很可能是proc.stdout.readline阻止了它。
标签: python python-2.7 tkinter subprocess