I can do the measure of text with tkFont, but I don't want a root window --> tk.Tk()
2 Answers
You did mean to ask: “How can I measure the width of a string rendering via tkFont without creating a window first?”
And the answer is: you can’t. Tk needs its root instance to do drawing and such.
you can however create it, measure your text, and immediately dispose of it via .delete(). When doing that, the window doesn’t appear for me.
3 Comments
flying sheep
No problem :D i hope i’m right, though, and there isn’t a fancy way to do it. (or actually i hope i’m wrong and you get what you wanted. i doubt it, though). I edited the answer, btw.
WinEunuuchs2Unix
A few lines of sample code with a string "THIS is a String" and the printed output with width would be helpful for the font and pixel width challenged like me :)
flying sheep
@WinEunuuchs2Unix I wrote this 13 years ago and haven’t touched Tk in the mean time, so feel free to do that yourself ;)