FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Document default tk Text class bindings for tkinter and IDLE · Issue #70273 · python/cpython · GitHub

Repository navigation

Document default tk Text class bindings for tkinter and IDLE #70273

Closed

Description

mannequin
BPO 26085
Nosy @terryjreedy, @serhiy-storchaka
Files
  • 2016-01-11--1452545267_1920x1080_scrot.png: My code and results
  • tem.py: Illustrate bug and fix
  • tem.tcl
  • 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 = None
    created_at = <Date 2016-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 = <Date 2016-10-25.06:59:21.287>
    user = 'https://bugs.python.org/freshnick'

    bugs.python.org fields:

    activity = <Date 2016-10-25.06:59:21.287>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Tkinter']
    creation = <Date 2016-01-11.21:12:36.847>
    creator = 'fresh_nick'
    dependencies = []
    files = ['41585', '41631', '41632']
    hgrepos = []
    issue_num = 26085
    keywords = []
    message_count = 5.0
    messages = ['258019', '258379', '258383', '279336', '279365']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'docs@python', 'serhiy.storchaka', 'fresh_nick']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26085'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    Linked PRs

    Activity

    1. freshnick commented on Jan 11, 2016

      freshnickmannequin
      MannequinAuthor

      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.

    2. terryjreedy commented on Jan 16, 2016

      Member

      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'.

    3. serhiy-storchaka commented on Jan 16, 2016

      Member

      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.

    4. serhiy-storchaka commented on Oct 24, 2016

      Member

      Does anybody want to provide documentation patch? Otherwise this issue will be closed as "not a bug".

    5. terryjreedy commented on Oct 25, 2016

      Member

      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.

    6. changed the title [-]Tkinter spoils the input text[/-] [+]Document default tk Text class bindings for tkinter and IDLE[/+] on Oct 25, 2016
    7. transferred this issue fromon Apr 10, 2022
    8. added 4 commits that reference this issue on Jun 27, 2026
    9. serhiy-storchaka commented on Jun 28, 2026

      Member

      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.

    10. serhiy-storchaka commented on Jul 1, 2026

      Member

      Done in #152389, which documents the default class bindings. Closing as resolved.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL