➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Text containing "wide" character not correctly refreshed
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.8
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: epaine, hejin517, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-12-28 15:01 by hejin517, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Screenshot 2021-12-28 201447.png epaine, 2021-12-28 20:31
Messages (2)
msg409258 - (view) Author: (hejin517) Date: 2021-12-28 15:01
When the app runs it first shows a black character "f" in Times New Roman.
By clicking the button, I expect that the color of the whole character will be changed to red, but actually only part is changed.

In FontForge (a font editor), I find the character "f" in Times New Roman is wider than its "width".
Please look into this problem. Thanks.

Code to reproduce:
----------------------
import tkinter

def change_color():
    canvas.itemconfig(text, fill="red")

root = tkinter.Tk()
canvas = tkinter.Canvas(root, width=500, height=500)
canvas.pack()

text = canvas.create_text((200, 200), text="f", font=("Times New Roman", 200), fill="black")

button = tkinter.Button(text="Change Color", command=change_color)
button.pack()

root.mainloop()
msg409271 - (view) Author: E. Paine (epaine) * Date: 2021-12-28 20:31
I have been able to reproduce this in Wish built from the current head. Interestingly, the cut-off seems to be 1px off what `font measure` gives (see attached). Though in this behaviour is a problem, the man page does note the following:
> The return value is the total width in pixels of text, not including the extra pixels used by highly exaggerated characters such as cursive “f” [https://www.tcl.tk/man/tcl/TkCmd/font.html#M10]

Tkinter is simply a thin wrapper of Tk, so I suggest you take it up with that team so they can fix it upstream (a minimal equivalent of your code in Tcl can be found below): https://core.tcl-lang.org/tk/reportlist

pack [canvas .c -width 250 -height 500]
font create .f -family "Times New Roman" -size -500
set t [.c create text 0 250 -text f -font .f -anchor w]
update ; # A window render is required for the bug to occur
.c itemconfigure $t -fill red
set x [font measure .f f]
.c create line $x 0 $x 500
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90347
2021-12-30 08:14:48serhiy.storchakasetstatus: open -> closed
resolution: third party
stage: resolved
2021-12-28 20:31:16epainesetfiles: + Screenshot 2021-12-28 201447.png
nosy: + serhiy.storchaka, epaine
messages: + msg409271

2021-12-28 15:01:14hejin517create