mainloop starts Tkinter’s event loop and keeps the GUI running. The loop redraws the window, processes user events, and invokes widget callbacks such as button commands until the window closes. Because the call blocks, long-running work inside a callback can freeze the interface. section 7.4.1
Listing 7.12 “Hello world” with Tkinter
import tkinter
from tkinter import ttk
window = tkinter.Tk()
window.title('Hello world app')
window.geometry('200x100')
def say_hello():
print('Hello there!')
hello_button = ttk.Button(window, text='Say hello', command=say_hello)
hello_button.pack()
window.mainloop()
A minimal Tkinter application creates a window, connects a button to a callback, and calls mainloop to begin processing events. section 7.4.1
Treat the Tk event loop as the application’s responsive center: web requests, large-file loads, or delays must not occupy it for long. A separate thread can host an asyncio event loop while Tkinter continues running mainloop, allowing progress updates and cancellation without freezing the GUI. section 7.4.1 section 7.4.2
