我怎样才能测量通过tkFont字符串渲染的宽度,而不是先创建一个窗口? [英] How can I measure the width of a string rendering via tkFont without creating a window first?

查看:110
本文介绍了我怎样才能测量通过tkFont字符串渲染的宽度,而不是先创建一个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用tkFont做文本的度量,但是我不想要一个根窗口 - > tk.Tk()

解决方案

div>

你的意思是问:我怎样才能测量通过 tkFont 字符串渲染的宽度,而不先创建一个窗口?



答案是:你不能。 Tk需要它的根实例来进行绘图等。然而,你可以创建它,测量你的文本,并立即通过 .delete( )。这太快了,窗户不会出现在我身上。


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

解决方案

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.

这篇关于我怎样才能测量通过tkFont字符串渲染的宽度,而不是先创建一个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆