Built-in virtual events#
A virtual event is a named notification in double brackets — <<Copy>>,
<<ThemeChanged>> — decoupled from any one physical event. Bind them exactly
like physical events. This page catalogs the ones Tk, ttk, and ttkbootstrap
define, and documents the methods that define your own. For how to use them, see
Events & callbacks.
Defining your own#
A virtual event is bound to one or more physical sequences; firing any of them
fires the virtual event. This is how you name an action once (<<Save>>) and
let each platform reach it by its own key.
- event_add(virtual, *sequences)
Map one or more physical sequences onto a virtual event, creating it if needed. Adds to any sequences already mapped.
- Parameters:
virtual (str) – the virtual event name, e.g.
"<<Save>>".sequences – physical sequences, e.g.
"<Control-s>","<F2>".
- Returns:
None.
- event_delete(virtual, *sequences)
Remove sequences from a virtual event. With no
sequences, removes every sequence mapped to it.- Parameters:
virtual (str) – the virtual event name.
sequences – the sequences to unmap; omit for all.
- Returns:
None.
- event_info(virtual=None)
Report the physical sequences mapped to a virtual event. Useful for asking what a built-in event is bound to on this platform —
event_info("<<Copy>>")answers('<Control-Key-c>', ...)on Windows and Linux but('<Mod1-Key-c>', ...)on macOS, where the copy key is Command.- Parameters:
virtual – a virtual event name; omit to list every defined virtual event.
- Returns:
the sequences mapped to
virtual, or the names of all virtual events when called with no argument.- Return type:
Editing & clipboard#
Defined by default with the key sequences shown; emitted by Text and
Entry widgets and safe to bind or generate yourself.
Virtual event |
Default sequence |
Meaning |
|---|---|---|
|
|
Cut the selection. |
|
|
Copy the selection. |
|
|
Paste the clipboard. |
|
|
Paste the X selection (middle-click). |
|
|
Undo. |
|
|
Redo. |
|
|
Select everything. |
|
|
Clear the selection. |
|
|
Toggle selection of the item under the pointer. |
|
|
Request a context menu (right-click). |
Focus traversal#
Virtual event |
Default key |
Meaning |
|---|---|---|
|
|
Move focus to the next widget. |
|
|
Move focus to the previous widget. |
Widget notifications#
Emitted by specific widgets when their selection or state changes — no default key sequence; you bind them to react to the widget. Read the current value from the widget in the handler.
Virtual event |
Emitted by |
|---|---|
|
|
|
|
|
|
<<TreeviewOpen>><<TreeviewClose>> |
|
|
|
|
|
|
|
Theme & locale (ttkbootstrap)#
Virtual event |
Fires when |
|---|---|
|
The theme is switched (delivered to every widget). Bind it to recolor
anything you drew yourself; for rebuilding a custom style prefer
|
|
The locale is switched via |