I'm designing the app in tkinter, I need to read line by line one file each second and view the results on the widgets, also each second. The problem is that my program is reading the whole file and only after this update my Gui.
class Gui(Frame):
def __init__(self, master):
super(Gui, self).__init__()
self.master = master
# ... here are my tkinter widgets
self.ser = None
self.start_update()
def start_update(self):
if self.ser is None:
self.ser = open("serial.txt") # open only once
self.updater()
def updater(self):
while True:
self.raw_line = self.ser.readline()
if self.raw_line:
# here I update labels with .configure() method
self.after(1000, self.updater)
else:
print('Probably end of file')
self.ser.close()
self.ser = None # can open again
root = Tk()
gui = Gui(root)
root.mainloop()