Tk Source Code

View Ticket
Login
Ticket UUID: 87bd2b899ae2c33d798885e34905c116dc5d06e9
Title: accessibility.tcl: the class defaults overwrite accessible names set by the application on every map (_init's "only once" guard never fires)
Type: Bug Version: 9.1
Submitter: anonymous Created on: 2026-10-03 17:36:34
Subsystem: (unused) Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-17 22:45:59
Resolution: Wont Fix Closed By: kevin_walzer
    Closed on: 2026-10-17 22:45:59
Description:
::tk::accessible::_init begins with

    if {[catch {::tk::accessible::get_acc_role $w} msg]} {
        if {$msg == $role} {
            return
        }
    }

which returns only when get_acc_role fails and its error message equals
the role, that is never, although the comment above it says the defaults
are set only once. So _init runs on every <Map> and resets role, name,
description, value, state and action to the class defaults. That
overwrites what the application set with ::tk::accessible::set_acc_*, both
before the widget is first mapped and after any re-map (pack forget + pack,
switching notebook tabs, a withdrawn toplevel shown again). This is on all
platforms; the output below is from X11.

"repro.tcl -names" on stock 9.1.0 (a screen reader, or any process named
"orca", must be running so that Tk loads accessibility.tcl):

    before map:    name=Open file / description=Open file
    after map:     name=Button / description=Open
    after re-map:  name=Button / description=Open

Simply returning when a role is already set would break Tk's own
refreshes, which rely on _init running again: the TNotebook
<<NotebookTabChanged>> binding updates the notebook's value to the current
tab through _init, and a re-map refreshes a widget's text.

Proposed fix (04.patch): _init remembers the values it set itself, per
widget (cleared on <Destroy>), and overwrites an attribute only when it is
unset or still holds the value that _init set last time. With it:

    before map:    name=Open file / description=Open file
    after map:     name=Open file / description=Open file
    after re-map:  name=Open file / description=Open file
    notebook value: General
    notebook value after selecting tab 2: Advanced

(The notebook lines are the same as without the patch.)

Attachments: