且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 tkinter 小部件中显示子进程的实时输出

更新时间:2023-02-26 17:29:31

我终于找到了解决方案.在窗口构建之后,必须添加:

Finally I found the solution. After the window construction, you must add :

frame.pack()
# force drawing of the window
win.update_idletasks()

然后在小部件中的每一行插入后,您还必须仅在小部件上使用相同的方法强制刷新.

And then after every line insertion in the widget, you must also force a refresh with the same method only on the widget.

# insert the line in the Text widget
t.insert(tk.END, out)
# force widget to display the end of the text (follow the input)
t.see(tk.END)
# force refresh of the widget to be sure that thing are displayed
t.update_idletasks()