Aug-18-2019, 08:47 AM
Hello,
I try to code a graphical interface to run terminal command to show the result in a label.
My problem is that the text of the label is only update when at the end of the subprocess.popen while I would like to see that the realtime updating of the label text accorindly to the stdout.
Please find below my code :
Could someone help me.
I try to code a graphical interface to run terminal command to show the result in a label.
My problem is that the text of the label is only update when at the end of the subprocess.popen while I would like to see that the realtime updating of the label text accorindly to the stdout.
Please find below my code :
from tkinter import *
from subprocess import Popen, PIPE
import io
class App(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.parent=parent
self.but=Button(text="Start", command=self.action)
self.but.pack()
self.lab=Label(parent, text='Text to display')
self.lab.pack()
self.lab.configure(width=50,height=100)
self.result=''
def action(self):
self.result=''
self.run('esptool.py --port /dev/ttyUSB0 flash_id')
def run(self,command):
process = Popen(command, stdout=PIPE, shell=True)
reader = io.TextIOWrapper(process.stdout, encoding='utf8')
while process.poll()==None:
char = reader.read(1)
self.result=self.result+char
print(self.result)
self.lab.configure(text=self.result)
if __name__ == "__main__":
Test=App()I think I need to use Thread but even if I have read a lot of article. I am block.Could someone help me.
