An Introduction to Tkinter
前页 | Chapter 44. Basic Widget Methods | 后页

# Event processing

## mainloop

`mainloop()`. Enter Tkinter's main event loop. To leave the event loop, use the quit method. Event loops can be nested; it's ok to call mainloop from within an event handler.

## quit

`quit()`. Leaves Tkinter's main event loop. Note that you can have nested event loops; each call to quit terminates the outermost event loop.

## update

`update()`. Process all pending events, call event callbacks, complete any pending geometry management, redraw widgets as necessary, and call all pending idle tasks. This method should be used with care, since it may lead to really nasty race conditions if called from the wrong place (from within an event callback, for example, or from a function that can in any way be called from an event callback, etc.)

## update_idletasks

`update_idletasks()`. Call all pending idle tasks, without processing any other events. This can be used to carry out geometry management and redraw widgets if necessary, without calling any callbacks.

## focus_set

`focus_set()`, `focus()`. Move keyboard focus to self. This means that all keyboard events sent to the application will be routed to self.

## focus_displayof

`focus_displayof()`.

## focus_force

`focus_force()`. Force keyboard focus to self.

FIXME: what's the difference between "moving" and "forcing"?

## focus_get

`focus_get()`.

## focus_lastfor

`focus_lastfor()`.

## tk_focus后页

`tk_focusNext()`. Return the next widget (following self) that should have focus. This is used by the default bindings for the Tab key.

## tk_focus前页

`tk_focusPrev()`. Return the previous widget (preceding self) that should have focus. This is used by the default bindings for the Shift-Tab key.

## grab_current

`grab_current()`.

## grab_release

`grab_release()`. Release the event grab.

## grab_set

`grab_set()`. Route all events for this application to self.

## grab_set_global

`grab_set_global()`. Route all events for the entire screen to self.

This should only be used in very special circumstances, since it blocks all other applications running on the same screen. And that probably includes your development environment, so you better make sure your application won't crash or lock up until it has properly released the grab.

## grab_status

`grab_status()`.

## wait_variable

`wait_variable(variable)`. Wait for the given Tkinter variable to change. This method enters a local event loop, so other parts of the application will still be responsive. The local event loop is terminated when the variable is updated (setting it to it's current value also counts).

## wait_visibility

`wait_visibility(widget)`. Wait for the given widget to become visible. This is typically used to wait until a new toplevel window appears on the screen. Like wait_variable, this method enters a local event loop, so other parts of the application will still work as usual.

## wait_window

`wait_window(widget)`. Wait for the given widget to be destroyed. This is typically used to wait until a destroyed window disappears from the screen. Like wait_variable and wait_visibility, this method enters a local event loop, so other parts of the application will still work as usual.

前页 | Home | 后页
Basic Widget Methods | Up | Event callbacks