[3.15] gh-156961: Fix tkinter.font.Font for a font name returned as a Tcl object (GH-157028) - #157403
Open
serhiy-storchaka wants to merge 1 commit into
Open
[3.15] gh-156961: Fix tkinter.font.Font for a font name returned as a Tcl object (GH-157028)#157403serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
…d as a Tcl object (pythonGH-157028) 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)
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.
Manual backport of GH-157028: the cherry-pick does not apply, because this branch has no wrapped font descriptions (gh-143990), so
Font.nameis always a string here and__str__needs a different fix. The test for wrapping a Tcl object as a font description is omitted for the same reason.Tk can return a font name 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 ofconfigure(). 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 withTclError: named font TkDefaultFont does not already exist.The object is now kept as is, so that it is passed back to Tk, which reuses the font resource cached in it. It is only converted where it is compared with a string.