Event Loop¶
Tk is event-based. When you click a Button
, a click event is
generated, and Tk processes it. Usually that involves making the button look
like it’s pressed down, and maybe calling a callback function that you have
told the button to run.
The event loop works essentially like this pseudo code:
while True:
handle_an_event()
if there_are_no_more_events_because_we_handled_all_of_them:
wait_for_more_events()
These functions can be used for working with the event loop:
-
teek.
quit
()[source]¶ Stop the event loop and destroy all widgets.
This function calls
destroy .
in Tcl, and that’s documented in destroy(3tk). Note that this function does not tell Python to quit; only teek quits, so you can do this:import teek window = teek.Window() teek.Button(window, "Quit", teek.quit).pack() teek.run() print("Still alive")
If you click the button, it interrupts
teek.run()
and the print runs.
-
teek.
before_quit
¶ quit()
runs this callback with no arguments before it does anything else. This means that when this callback runs, widgets have not been destroyed yet, but they will be destroyed soon.
-
teek.
update
(*, idletasks_only=False)[source]¶ Handles all pending events, and returns when they are all handled.
See update(3tcl) for details. If
idletasks_only=True
is given, this callsupdate idletasks
; otherwise, this callsupdate
with no arguments.