Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/terryjreedy'closed_at=Nonecreated_at=<Date2016-01-11.21:12:36.847>labels= ['3.7', 'type-bug', 'expert-tkinter', 'docs']
title='Document default tk Text class bindings for tkinter and IDLE'updated_at=<Date2016-10-25.06:59:21.287>user='https://bugs.python.org/freshnick'
Hello, I have Python 3.4.3 and Tk/Tcl 8.5 (built in Python; reported by tk.TclVersion and tk.TkVersion). When I assign printing 'This works' to a hotkey, the program prints 'This worsk'. After pressing the hotkey again, 'worsk' is replaced with 'works', but when the hotkey is pressed repeatedly, we can see 'worsk' sometimes (see the attachment).
You should have uploaded your .py file. Mine is attached, with fix added. Anyway, confirmed with 3.5.1, Win10. Slightly more bizarre than described, in that misspelling disappears on even insertion and reappears in odd insertion.
this worsk
this worksthis works
this worksthis worksthis worsk
Even stranger, printing the txt to Shell after the insertion shows the opposite parity.
this works
this worksthis worsk
this worksthis worksthis works
Binding to another key removes the problem. By experiment, ^t in Text means 'transpose chars to left and right of cursor and move cursor right' or equivalently, 'move char to right before the one on left'. So 'abc|def' becomes 'abdc|ef' (where '|' here represents the cursor, not a character. The exception is that at the end of the text, the two chars to the left are transposed, so that 'abc|' becomes 'acb|'.
Tk.bind has an 'add' parameter that defaults to None, which should mean 'replace previous bindings'. But I suspect that this only applies to user-added bindings, so not replacing a default Text binding is not considered a bug.
Serhiy, am I correct here or is this a tk or tkinter bug?
In fact, it seems that this default binding cannot be unbound. Adding 'txt.unbind('<Control-c>') did not work. Adding "return 'break'" at the end of the callback does work.
Bottom line: make sure that you bind to an unused sequence or add the return to disable any unused binding you do not know about.
Our doc is deficient, but correcting that is beyond the scope of this issue. Unless I have missed something, this should be closed as 'not a bug'.
I can't reproduce the result with tem.py. If change binding to <Control-t> and comment out the line "return 'break'" in the callback I can reproduce it.
This is expected and documented (but only in bind() docstring) behavior. If the callback returns 'break', no other functions (including standard handlers) will be invoked for the event. Otherwise the standard handler for <Control-t> is invoked and it swaps two characters as Terry said.
If doesn't consider this issue as the documentation issue, it should be closed as not a bug.
I want to recast this as a doc issue. The BINDINGS section of http://www.tcl.tk/man/tcl8.6/TkCmd/text.htm, near the bottom, has a list with 33 numbered items. The main categories of action include selection modification, cursor movement, and text deletion. Minor categories include insertion, transposition, undo/redo. However, the items are not neatly grouped this way.
Some of this IDLE doc is wrong, at least for IDLE, at least on Windows. For instance, at least on Windows, ^a in IDLE is Select All, not Move Beginning of Line.
For working on IDLE, it would be very helpful to have a *categorized* listing of class-bound actions that are verified to work for tkinter Text, with notes on any OS differences. I can then check what works on IDLE and how it changes the bindings on either some or all systems. I can and someday will do this for Windows, but I currently would need help for other OSes.
To help people avoid clashes such as Nick ran into, the tkinter doc should also have a sorted and abbreviated list of bound event sequences. "Text comes with bindings for the following event sequences for keys: Control-a, ..., z; Control-Shift-?, ...,z, Meta-...(Unix), Command-...(Mac). For mice, ..." Follow with a note on what can or cannot be unbound and the need to use 'break' when overriding.
A function to produce for IDLE a similar list that includes IDLE's system-specific add-ons and a user's customizations, would be a separate but very useful issue. Not knowing current bindings makes customization hard. Another spinoff issue would be making actions available via the IDLE menu system.
GH-152389 documents that widgets inherit Tk's class bindings and how to suppress one with "break" — which resolves the original report here.
@terryjreedy, your 2016 proposal for a categorized, per-OS-verified table of the ~33 Text bindings (plus the IDLE-bindings-dump and menu spinoffs) is a much bigger, ongoing effort that doesn't fit this issue.
Suggest closing this as resolved by GH-152389 and opening a fresh, narrower issue for the binding table. Keeping this open as the tracker for that table is fine too — your call.
Activity
freshnick commented on Jan 11, 2016
Hello, I have Python 3.4.3 and Tk/Tcl 8.5 (built in Python; reported by tk.TclVersion and tk.TkVersion). When I assign printing 'This works' to a hotkey, the program prints 'This worsk'. After pressing the hotkey again, 'worsk' is replaced with 'works', but when the hotkey is pressed repeatedly, we can see 'worsk' sometimes (see the attachment).
Have a nice day.
terryjreedy commented on Jan 16, 2016
You should have uploaded your .py file. Mine is attached, with fix added. Anyway, confirmed with 3.5.1, Win10. Slightly more bizarre than described, in that misspelling disappears on even insertion and reappears in odd insertion.
this worsk
this worksthis works
this worksthis worksthis worsk
Even stranger, printing the txt to Shell after the insertion shows the opposite parity.
this works
this worksthis worsk
this worksthis worksthis works
Binding to another key removes the problem. By experiment, ^t in Text means 'transpose chars to left and right of cursor and move cursor right' or equivalently, 'move char to right before the one on left'. So 'abc|def' becomes 'abdc|ef' (where '|' here represents the cursor, not a character. The exception is that at the end of the text, the two chars to the left are transposed, so that 'abc|' becomes 'acb|'.
Tk.bind has an 'add' parameter that defaults to None, which should mean 'replace previous bindings'. But I suspect that this only applies to user-added bindings, so not replacing a default Text binding is not considered a bug.
Serhiy, am I correct here or is this a tk or tkinter bug?
In fact, it seems that this default binding cannot be unbound. Adding 'txt.unbind('<Control-c>') did not work. Adding "return 'break'" at the end of the callback does work.
Bottom line: make sure that you bind to an unused sequence or add the return to disable any unused binding you do not know about.
Our doc is deficient, but correcting that is beyond the scope of this issue. Unless I have missed something, this should be closed as 'not a bug'.
serhiy-storchaka commented on Jan 16, 2016
I can't reproduce the result with tem.py. If change binding to <Control-t> and comment out the line "return 'break'" in the callback I can reproduce it.
This is expected and documented (but only in bind() docstring) behavior. If the callback returns 'break', no other functions (including standard handlers) will be invoked for the event. Otherwise the standard handler for <Control-t> is invoked and it swaps two characters as Terry said.
If doesn't consider this issue as the documentation issue, it should be closed as not a bug.
Here is Terry's example translated to pure Tcl.
serhiy-storchaka commented on Oct 24, 2016
Does anybody want to provide documentation patch? Otherwise this issue will be closed as "not a bug".
terryjreedy commented on Oct 25, 2016
I want to recast this as a doc issue. The BINDINGS section of http://www.tcl.tk/man/tcl8.6/TkCmd/text.htm, near the bottom, has a list with 33 numbered items. The main categories of action include selection modification, cursor movement, and text deletion. Minor categories include insertion, transposition, undo/redo. However, the items are not neatly grouped this way.
Some of these actions are IDLE menu items and are listed in the IDLE menu doc. Many more are documented in https://docs.python.org/3/library/idle.html#editing-and-navigation. Some useful actions, such as ^t Tranposition Right, are omitted.
Some of this IDLE doc is wrong, at least for IDLE, at least on Windows. For instance, at least on Windows, ^a in IDLE is Select All, not Move Beginning of Line.
For working on IDLE, it would be very helpful to have a *categorized* listing of class-bound actions that are verified to work for tkinter Text, with notes on any OS differences. I can then check what works on IDLE and how it changes the bindings on either some or all systems. I can and someday will do this for Windows, but I currently would need help for other OSes.
To help people avoid clashes such as Nick ran into, the tkinter doc should also have a sorted and abbreviated list of bound event sequences. "Text comes with bindings for the following event sequences for keys: Control-a, ..., z; Control-Shift-?, ...,z, Meta-...(Unix), Command-...(Mac). For mice, ..." Follow with a note on what can or cannot be unbound and the need to use 'break' when overriding.
A function to produce for IDLE a similar list that includes IDLE's system-specific add-ons and a user's customizations, would be a separate but very useful issue. Not knowing current bindings makes customization hard. Another spinoff issue would be making actions available via the IDLE menu system.
gh-70273: Document default class bindings in tkinter (GH-152389)
[3.13] gh-70273: Document default class bindings in tkinter (GH-152389)…
[3.14] gh-70273: Document default class bindings in tkinter (GH-152389)…
[3.15] gh-70273: Document default class bindings in tkinter (GH-152389)…
serhiy-storchaka commented on Jun 28, 2026
GH-152389 documents that widgets inherit Tk's class bindings and how to suppress one with "break" — which resolves the original report here.
@terryjreedy, your 2016 proposal for a categorized, per-OS-verified table of the ~33 Text bindings (plus the IDLE-bindings-dump and menu spinoffs) is a much bigger, ongoing effort that doesn't fit this issue.
Suggest closing this as resolved by GH-152389 and opening a fresh, narrower issue for the binding table. Keeping this open as the tracker for that table is fine too — your call.
serhiy-storchaka commented on Jul 1, 2026
Done in #152389, which documents the default class bindings. Closing as resolved.