gh-143990: Allow tkinter.font.Font to wrap a font description#152025
Open
serhiy-storchaka wants to merge 2 commits into
Open
gh-143990: Allow tkinter.font.Font to wrap a font description#152025serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
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>
Documentation build overview
|
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By default :class:
tkinter.font.Fontcreates a new named font from the given description (via Tcl'sfont create) and then uses its name in :meth:~tkinter.font.Font.actual, :meth:~tkinter.font.Font.measureand :meth:~tkinter.font.Font.metrics. There is a loss of precision between the description and the created font, so aFontobject can behave differently from the equivalent description tuple (gh-143990).This adds a wrap mode: with
exists=Trueand noname, 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:!nameattribute is the description itself rather than a string (formatted viatkinter._joinwhen 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