Aug-09-2021, 04:30 PM
tkinter updates things when your program is idle. Normally this is what you want to happen. If you have something that takes a long time to complete you should break it up into smaller pieces of processing, or run it in a thread or parallel process. This way your GUI is still responsive to user actions.
You will not see anything before mainloop() is called. Here is a much longer delay with a lot less going on.
You will not see anything before mainloop() is called. Here is a much longer delay with a lot less going on.
import tkinter as tk import time start = time.time() root = tk.Tk() tk.Label(root, text='Hello World!').pack() print(time.time() - start) time.sleep(5) root.mainloop()If you don't care about having a responsive interface, you can call update() to update your widgets.
import tkinter as tk import time start = time.time() root = tk.Tk() tk.Label(root, text='Hello World!').pack() root.update() print(time.time() - start) time.sleep(5) root.mainloop()This draws the window right away, but the window is unresponsive and you get a busy cursor until the program wakes up from its 5 second nap.