Display realtime output of a subprocess in a tkinter widget

前端 未结 3 1679
灰色年华
灰色年华 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条回答
  •  死守一世寂寞
    2020-11-27 22:22

    Just in case someone else is looking for it...

    log_box_1 = tk.Text(root, borderwidth=3, relief="sunken")
    
    with subprocess.Popen("ls -la", shell=True, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
                for line in p.stdout:
                    log_box_1.insert(tk.END, line)
    

    From here

提交回复
热议问题