Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-156961: Fix tkinter.font.Font for a font name returned as a Tcl object - #157028

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:tkinter-font-tcl-object
Sep 13, 2026
Merged

gh-156961: Fix tkinter.font.Font for a font name returned as a Tcl object#157028
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:tkinter-font-tcl-object

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 6, 2026

Copy link
Copy Markdown
Member

Tk can return a font name or description as a Tcl object rather than a string, for example from ttk.Style().lookup("TButton", "font"), Menu.entrycget("font"), ttk.Entry.cget("font"), or the default value in the result of configure(). Such an object does not compare equal to a string, so it was not recognized as the name of an existing named font, and the code from the issue failed with TclError: named font TkDefaultFont does not already exist. Wrapping a font description also failed, with TypeError: '_tkinter.Tcl_Obj' object is not iterable.

The object is now kept as is, so that it is passed back to Tk, which reuses the font resource cached in it (this is why FromObj() does not convert fonts to strings, see gh-153513). It is only converted where it is compared with a string.

Tested with Tcl/Tk 8.6.17, 8.7b1, 9.0.4 and 9.1b1, with and without wantobjects.

The backports to 3.15, 3.14 and 3.13 need to be made manually: these branches have no wrapped font descriptions (gh-143990), so Font.name is always a string there and __str__ needs a different fix.

🤖 Generated with Claude Code

…Tcl object

Tk can return a font name or description as a Tcl object, for example
from ttk.Style().lookup("TButton", "font"), Menu.entrycget("font"),
ttk.Entry.cget("font"), or the default value in the result of
configure().  Such an object does not compare equal to a string, so it
was not recognized as the name of an existing named font.  Keep it as
is, so that it is passed back to Tk, and only convert it where it is
compared with a string.
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 6, 2026
@serhiy-storchaka serhiy-storchaka added needs backport to 3.14 bugs and security fixes needs backport to 3.13 bugs and security fixes labels Sep 6, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 62cbd34 into python:main Sep 13, 2026
59 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the tkinter-font-tcl-object branch September 13, 2026 08:03
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 62cbd34df74e4e07bb50edcaeec7454e71da47ce 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 62cbd34df74e4e07bb50edcaeec7454e71da47ce 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 62cbd34df74e4e07bb50edcaeec7454e71da47ce 3.13

@bedevere-app

bedevere-app Bot commented Sep 13, 2026

Copy link
Copy Markdown

GH-157403 is a backport of this pull request to the 3.15 branch.

@bedevere-app

bedevere-app Bot commented Sep 13, 2026

Copy link
Copy Markdown

GH-157404 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed needs backport to 3.15 pre-release feature fixes, bugs and security fixes needs backport to 3.14 bugs and security fixes labels Sep 13, 2026
@bedevere-app

bedevere-app Bot commented Sep 13, 2026

Copy link
Copy Markdown

GH-157405 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 13, 2026
serhiy-storchaka added a commit that referenced this pull request Sep 13, 2026
… Tcl object (GH-157028) (GH-157405)

Tk can return a font name as a Tcl object, for example from
ttk.Style().lookup("TButton", "font"), Menu.entrycget("font"),
ttk.Entry.cget("font"), or the default value in the result of
configure().  Such an object does not compare equal to a string, so it
was not recognized as the name of an existing named font.  Keep it as
is, so that it is passed back to Tk, and only convert it where it is
compared with a string.

(cherry picked from commit 62cbd34)
serhiy-storchaka added a commit that referenced this pull request Sep 13, 2026
… Tcl object (GH-157028) (GH-157404)

Tk can return a font name as a Tcl object, for example from
ttk.Style().lookup("TButton", "font"), Menu.entrycget("font"),
ttk.Entry.cget("font"), or the default value in the result of
configure().  Such an object does not compare equal to a string, so it
was not recognized as the name of an existing named font.  Keep it as
is, so that it is passed back to Tk, and only convert it where it is
compared with a string.

(cherry picked from commit 62cbd34)
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