Title: Document default tk Text class bindings for tkinter and IDLE
Type: behavior Stage: needs patch
Components: Documentation, Tkinter Versions: Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: docs@python, fresh_nick, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2016-01-11 21:12 by fresh_nick, last changed 2016-10-25 06:59 by terry.reedy.

File name Uploaded Description Edit
2016-01-11--1452545267_1920x1080_scrot.png fresh_nick, 2016-01-11 21:12 My code and results terry.reedy, 2016-01-16 10:29 Illustrate bug and fix
tem.tcl serhiy.storchaka, 2016-01-16 11:23
Messages (5)
msg258019 - (view) Author: fresh_nick (fresh_nick) Date: 2016-01-11 21:12
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.
msg258379 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-01-16 10:29
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'.
msg258383 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-16 11:23
I can't reproduce the result with 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.
msg279336 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-24 19:59
Does anybody want to provide documentation patch? Otherwise this issue will be closed as "not a bug".
msg279365 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-10-25 06:59
I want to recast this as a doc issue.  The BINDINGS section of, 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  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.
Date User Action Args
2016-10-25 06:59:21terry.reedysetversions: + Python 3.6, Python 3.7
title: Tkinter spoils the input text -> Document default tk Text class bindings for tkinter and IDLE
messages: + msg279365

assignee: docs@python -> terry.reedy
stage: needs patch
2016-10-24 19:59:17serhiy.storchakasetnosy: + docs@python
messages: + msg279336

assignee: docs@python
components: + Documentation
2016-01-16 11:23:56serhiy.storchakasetfiles: + tem.tcl

messages: + msg258383
2016-01-16 10:29:48terry.reedysetfiles: +
versions: + Python 3.5, - Python 3.4
nosy: + terry.reedy, serhiy.storchaka

messages: + msg258379
2016-01-11 21:12:36fresh_nickcreate