Display realtime output of a subprocess in a tkinter widget

前端 未结 3 1684
灰色年华
灰色年华 2020-11-27 21:45

My question is almost the same as this one: Widget to Display subprocess stdout? but a step further.

I have the following code (python2.7):

def btnGo         


        
3条回答
  •  猫巷女王i
    2020-11-27 22:41

    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()
    

提交回复
热议问题