什么决定了 Tkinter Text 小部件的大小?

编程入门 行业动态 更新时间:2024-10-28 16:21:52
本文介绍了什么决定了 Tkinter Text 小部件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试缩小文本小部件的宽度以适应内容.

如果我使用,

<预><代码>>>>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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:25:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:部件   大小   决定了   Text   Tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!