I am trying to update text in a scrolltext widget within a for loop. The print statement shows the updated text each time through the loop but the I don't see anything in the Tk window until the loop has completed. Then I see '('This is ', 4, ' times though the loop.')'. I never see 0 through 3 being displayed.
from tkinter import *
from tkinter import scrolledtext
import time
main = Tk()
main.title("test_loop")
main.geometry('750x625')
main.configure(background='ivory3')
def show_msg():
global texw
textw = scrolledtext.ScrolledText(main,width=40,height=25)
textw.grid(column=0, row=1,sticky=N+S+E+W)
textw.config(background="light grey", foreground="black",
font='arial 20 bold', wrap='word', relief="sunken", bd=5)
for i in range(5):
txt = "This is ", i, " times though the loop."
txt = str(txt)
print(txt)
textw.delete('1.0', END) # Delete any old text on the screen
textw.update() # Clear the screen.
textw.insert(END, txt) # Write the new data to the screen
time.sleep(5)
btn = Button(main, text = 'display_log', bg='light grey', width = 15,
font='arial 12', relief="raised",bd=5,command = show_msg)
btn = btn.grid(row = 0, column = 0)
main.mainloop()

