小编Mik*_*ane的帖子

随着字符串的增长,字体中的 Tkinter 字符串测量值与文本小部件中的测量值不同

保存字符串(以指定字体)的 Text 对象似乎根据字符串的长度给出不一致的结果。例如:

from Tkinter import *
import tkFont
root=Tk()
t_Font = tkFont.Font(family='Helvetica', size=12, weight='bold')
t_text='New.'
t_frame = Frame(root, bd=0, height=10, width=t_Font.measure(t_text))
t = Text(master=t_frame, height=1, width=len(t_text), bd=1, font=t_Font, padx=0)
print '\n\nMeasured:', t_Font.measure(t_text), 'Frame req:', \
      t_frame.winfo_reqwidth(), 'As Text:', t.winfo_reqwidth()
Run Code Online (Sandbox Code Playgroud)

Measured: 38 Frame req: 38 As Text: 38

t_text='New title.'
t_frame = Frame(root, bd=0, height=10, width=t_Font.measure(t_text))
t = Text(master=t_frame, height=1, width=len(t_text), bd=1, font=t_Font, padx=0)
print '\n\nMeasured:', t_Font.measure(t_text), 'Frame req:', \
      t_frame.winfo_reqwidth(), 'As Text:', t.winfo_reqwidth()
Run Code Online (Sandbox Code Playgroud)

Measured: 69 Frame req: 69 As …

python text tkinter measurement frame

3
推荐指数
1
解决办法
2779
查看次数

标签 统计

frame ×1

measurement ×1

python ×1

text ×1

tkinter ×1