Skip to content

gh-143990: Allow tkinter.font.Font to wrap a font description#152025

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:tkinter-font-wrap-description
Open

gh-143990: Allow tkinter.font.Font to wrap a font description#152025
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:tkinter-font-wrap-description

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

By default :class:tkinter.font.Font creates a new named font from the given description (via Tcl's font create) and then uses its name in :meth:~tkinter.font.Font.actual, :meth:~tkinter.font.Font.measure and :meth:~tkinter.font.Font.metrics. There is a loss of precision between the description and the created font, so a Font object can behave differently from the equivalent description tuple (gh-143990).

This adds a wrap mode: with exists=True and no name, the font description is wrapped as is, without creating a named font, so that it is used without loss of precision and renders identically to the raw description when used as a widget option. In this case the :attr:!name attribute is the description itself rather than a string (formatted via tkinter._join when used as an option value, the same way ttk formats its style values).

Keeping the description as name (rather than a stringified form) keeps __eq__ correct: a wrapped description never accidentally equals a named font whose name happens to be its string form.

Keyword options now also override the corresponding attributes of the given font instead of being silently ignored.

(There is also an open PR #143992 taking a narrower "preserve negative pixel sizes" approach to the same issue; this is the more general fix.)

🤖 Generated with Claude Code

With exists=True and no name, Font now wraps the font description as is,
without creating a new named font, so that it is used without loss of
precision by actual(), measure() and metrics().  Its name attribute is then
the description rather than a string.  Keyword options now override the
corresponding settings of the given font instead of being ignored.

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

read-the-docs-community Bot commented Jun 23, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33276761 | 📁 Comparing bdac908 against main (7928a8b)

  🔍 Preview build  

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

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant