Search code examples
pythonfontstkinter

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


Solution

  • 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.