Skip to content

Add missing symbolic constants to tkinter.constants #159301

Open

Description

@serhiy-storchaka

Proposal:

tkinter.constants provides symbolic constants for the enumerated keywords of the Tk API, such as END, RAISED or CASCADE, and they are re-exported from tkinter.
It is essentially complete for the classic widgets as they were in Tk 8.0, but it was never extended for keywords added later, and it contains no ttk keywords at all.

Tk defines its enumerated option values in string tables (const char *const ...Strings[]) used with Tcl_GetIndexFromObj or as TK_OPTION_STRING_TABLE option specs.
Of the 174 keyword slots in these sets, tkinter.constants covers 121, so 47 distinct keywords have no constant.

I propose to add 39 of them:

option names
-labelanchor EN ES WN WS
-compound (themed widgets) TEXT IMAGE
-bordermode IGNORE
-direction ABOVE BELOW FLUSH
-stretch ALWAYS MIDDLE NEVER
-tabstyle TABULAR WORDPROCESSOR
-insertunfocussed HOLLOW Tk 8.6+
-mode DETERMINATE INDETERMINATE
-selecttype ITEM CELL Tk 9.0+
-show TREE HEADINGS
-state READONLY
themed widget states ALTERNATE BACKGROUND FOCUS HOVER INVALID PRESSED SELECTED
themed widget states LEAF OPEN Tk 9.1+
-validate KEY FOCUSIN FOCUSOUT
validation reasons FORCED
-type of Menu MENUBAR TEAROFF
yview scroll PIXELS

All other names are available in all supported Tk versions, starting from 8.5.

The remaining missing keywords are not worth a constant: the themed user1-user6 states are user-defined placeholders, and the -size values of ttk.Toggleswitch are the digits 1, 2 and 3, which would clash confusingly with the integer TRUE = 1.

This came up in #158328, where adding the symbolic color names was rejected.
Unlike color names, these are small closed sets fixed by Tk, which is what tkinter.constants is for.

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    stdlibStandard Library Python modules in the Lib/ directory
    3.16new features, bugs and security fixes
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-tkintertype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions