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

前端 未结 2 1400

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

2条回答
  •  再見小時候
    2020-12-19 15:57

    You did mean to ask: “How can I measure the width of a string rendering via tkFont without creating a window first?”

    An the answer is: you can’t. Tk needs it’s root instance to do drawing and such.

    you can however create it, measure your text, and immediately dispose it via .delete(). This is so fast that the window doesn’t appear for me.

提交回复
热议问题