Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

python - How can I measure the width of a string rendering via tkFont without creating a window first?

I can do the measure of text with tkFont, but I don't want a root window --> tk.Tk()

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Now I have this, and it works

root = tk.Tk()
font = tkFont.Font(family=fn, size=fs)
w, h = (font.measure(text), font.metrics("linespace"))
root.destroy()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...