Skip to content

gh-153513: Return str and numbers for more Tcl object types in _tkinter#153514

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:tkinter-fromobj-types
Jul 10, 2026
Merged

gh-153513: Return str and numbers for more Tcl object types in _tkinter#153514
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:tkinter-fromobj-types

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 10, 2026

Copy link
Copy Markdown
Member

With wantobjects enabled (the default), FromObj() now converts a few more Tcl object types to the natural Python type instead of wrapping them in an opaque _tkinter.Tcl_Obj.

str for types whose internal representation is only a throwaway, context-bound lookup with nothing worth preserving for a round-trip back to Tcl: index (an enumeration keyword, e.g. the value of -orient or -state), window (e.g. -labelwidget), nsName (a namespace name) and parsedVarName (e.g. -variable). An index value is always one of a small fixed set of keywords, so the resulting str is interned — equal keywords share a single object.

int/float for the pixel type: a screen distance with no unit suffix is already in pixels and screen-independent, so it is returned as a number. A distance with an m/c/i/p suffix depends on the screen resolution and needs a Tk_Window to resolve (not available in FromObj()), so it is kept as a Tcl_Obj.

Deliberately left as Tcl_Obj: color, border, font and cursor, whose internal representation caches an allocated X/font resource that Tk reuses when the object is passed back; and dict, a structured value best consumed with _splitdict().

Only the object mode is affected; with wantobjects disabled everything is already str. Verified across Tcl/Tk 8.6, 8.7, 9.0 and 9.1, with wantobjects both enabled and disabled. The unit-bearing-distance-stays-Tcl_Obj behavior is Tk 9.0+ only (classic-widget cget on Tk < 9 eagerly resolves a unit-bearing distance to an integer pixel count), and the nsName object type exists only on Tk 9.0+.

🤖 Generated with Claude Code

…_tkinter

FromObj() now returns str for the "index", "window", "nsName" and
"parsedVarName" object types, whose internal representation is only a
context-bound lookup with nothing worth preserving in a Tcl_Obj.  An
"index" value is one of a small fixed set of enumeration keywords, so
its str is interned.

A "pixel" screen distance with no unit suffix is screen independent and
is now returned as an int or float.  A distance with an m/c/i/p suffix
needs a Tk_Window to be resolved and is kept as a Tcl_Obj, as are the
"dict" and the resource types "color", "border", "font" and "cursor".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33531001 | 📁 Comparing 3bd09b7 against main (c98e984)

  🔍 Preview build  

3 files changed
± library/tkinter.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@serhiy-storchaka serhiy-storchaka merged commit 8a32914 into python:main Jul 10, 2026
56 checks passed
@serhiy-storchaka serhiy-storchaka deleted the tkinter-fromobj-types branch July 10, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant