I am trying to output live stdout
and stderr
to a ScrolledText
widget. I have gotten the live output fine, but the ScrolledText
widget is not updating until the script is finally executed. I tested this on a simpler example to see if it was the time in between stdout lines. I insert a time.sleep(1)
call before I insert the text to the ScrollText
widget. Can someone explain to me why the ScrolledText
widget doesn't update after every scroll_object.insert(tk.INSERT,string)
call?
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
import time
def insert_stuff(scroll_object):
for i in range(10):
time.sleep(1)
string = f'{i}\n'
scroll_object.insert(tk.INSERT,string)
root = tk.Tk()
output = ScrolledText(root)
button = tk.Button(window,text='Insert Text', command = lambda: insert_stuff(output))
output.pack()
button.pack()
window.mainloop()