| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead. |
Sorry, something went wrong.
|
Thank you. I wasn't sure where to comment this, but I found a case where the error wasn't fixed. import tkinter as tk
import tkinter.font as tkfont
root = tk.Tk()
font_tuple = ("Calibri", -14)
# font = tkfont.Font(root, font_tuple)
lb1 = tk.Label(root, text="Hello", font=font_tuple)
lb1.pack()
font = tkfont.Font(root, lb1["font"]) #
lb2 = tk.Label(root, text="Hello", font=font)
lb2.pack()
root.update()
print(lb1.winfo_width(), lb1.winfo_height())
print(lb2.winfo_width(), lb2.winfo_height())
root.mainloop() |
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
|
#152025 is an alternative solution which allows to wrap a font description, not only a named font. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
gh-143990: Preserve negative pixel sizes in tkinter.font.Font
Summary
This PR fixes a bug where tkinter.font.Font objects would lose their negative sign (representing pixel size) and convert it to a positive integer (representing points) during initialization.
details
The Font.init method calls tk.call("font", "actual", font). In Tcl/Tk, font actual resolves the requested font to the system's closest match. If a font is requested in pixels (e.g., -14), Tcl calculates the equivalent point size (e.g., 11) based on the current DPI.
The current implementation in tkinter/font.py was blindly accepting this resolved value and overwriting the user's original request. This fix checks if the input was a tuple containing a size, and if so, restores that specific size after the font actual call.
Changes
Modified Lib/tkinter/font.py to preserve the user-requested size.
Added a regression test test_negative_pixel_size to Lib/test/test_tkinter/test_font.py.
Verified that Font.cget("size") now returns the correct negative integer.