I create a simple GUI which contain a button and a text widget (TextArea). My business is when I click the button, the text widget will be insert some text.
At my attached image, After the GUI appeared, I clicked the button and I'm in breakpoint at line 9, my expectation is the text widget have 2 lines: text1, text2
However, nothing is showed until the function callback is finished
from tkinter import *
master = Tk()
def callback(text: Text):
text.delete('1.0', END)
text.insert(END, 'text1\r\n')
text.insert(END, 'text2\r\n')
text.insert(END, 'text3\r\n')
text.insert(END, 'text4\r\n')
text.insert(END, 'text5\r\n')
text.insert(END, 'text6\r\n')
text.insert(END, 'text7\r\n')
textwidget = Text(master)
textwidget .pack()
b = Button(master, text="OK", command=lambda :callback(textwidget))
b.pack()
mainloop()
My question is How can I force the gui update immediately after execute insert method of textwidget.
Update
Thank you for @Saad recommendation, I update the code (insert text.update() at line 9) and I can see the text appear in text widget
def callback(text: Text):
text.delete('1.0', END)
text.insert(END, 'text1\r\n')
text.insert(END, 'text2\r\n')
text.update()
text.insert(END, 'text3\r\n')
text.insert(END, 'text4\r\n')
text.insert(END, 'text5\r\n')
text.insert(END, 'text6\r\n')
text.insert(END, 'text7\r\n')