Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()

like image 808
Alquimista Avatar asked Feb 24 '23 04:02

Alquimista


1 Answers

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()
like image 85
Alquimista Avatar answered Apr 29 '23 21:04

Alquimista