Message409004
(This is behavior, not crash issue, as the latter is when there is no traceback.)
The editor code was added 3 years ago in #37929, PR-15452, to correct using the configured char width after font and window size changes make that invalid. It is based on
https://www.tcl.tk/man/tcl8.6/TkCmd/text.html#M21
"If the font does not have a uniform width then the width of the character “0” [zero] is used in translating from character units to screen units." The implies that said char width is non-zero. It would seem like a font bug if not. This is first report I know of where width is 0.
The current code implements this as
zero_char_width = \
Font(text, font=text.cget('font')).measure('0')
Matej, what OS and font gives this error? Please run the following, also uploaded, with the offending font, replacing the name I used.
import tkinter as tk
from tkinter.font import Font
r = tk.Tk()
t = tk.Text(r, font=('Source Code Pro', 10, 'normal'))
t.pack()
s = '0oO !*}'
t.insert('1.0', s) # Only to check that all above is valid.
for c in s:
print(Font(t, font=t['font']).measure(c))
For fixed 10 pitch Source Code Pro, all widths are 8.
---
We could, of course, catch ZeroDivisionError, but when then? This is why I want to know what OS, font, and a test with multiple characters.
On possibility is to check whenever font is set, but still, what then? |
|
Date |
User |
Action |
Args |
2021-12-22 00:32:00 | terry.reedy | set | recipients:
+ terry.reedy, taleinat, mcepl |
2021-12-22 00:32:00 | terry.reedy | set | messageid: <1640133120.5.0.773675438632.issue46146@roundup.psfhosted.org> |
2021-12-22 00:32:00 | terry.reedy | link | issue46146 messages |
2021-12-22 00:32:00 | terry.reedy | create | |
|