什么决定了 Tkinter Text 小部件的大小? [英] What determines the size of a Tkinter Text widget?
本文介绍了什么决定了 Tkinter Text 小部件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试缩小文本小部件的宽度以适应内容.
如果我使用,
<预><代码>>>>tktext.config(宽度=250)>>>tktext.winfo_width()650为什么会这样?决定小部件宽度的所有因素是什么?
解决方案
您看到差异的原因是:
width
选项以字符单位*为单位设置文本框的宽度..winfo_width
方法返回以像素为单位的宽度.
这两个不一定必须相同(很少是相同的).
*注意:我找不到 Tkinter.Text
width
选项的好链接,所以我添加了一个对于 Tkinter.Entry
width
选项,原理相同.
I\m trying to shrink the width of my Text widget to fit the contents.
if I use,
>>> tktext.config(width=250)
>>> tktext.winfo_width()
650
Why does this happen? What are all the factors that determine a widget's width?
解决方案
The reason that you are seeing the discrepancy is thus:
- The
width
option sets the width of the textbox in character units*. - The
.winfo_width
method returns the width in pixels.
These two do not necessarily have to be the same (and rarely are).
*Note: I couldn't find a good link for the Tkinter.Text
width
option, so I added one for the Tkinter.Entry
width
option, which has the same principle.
这篇关于什么决定了 Tkinter Text 小部件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文