Tkinter文本窗口小部件设置选项卡

问题描述 投票:3回答:1

我必须将我的文本小部件的标签大小设置为4个字符。当我做textwidget.config(tabs = ("4c","8c"))我没有得到所需的结果。它的制表符很多,现在是4个字符。设置tabs属性时我做错什么了吗?另外,当我显示行号和列号时,我会通过获取插入物的索引来做到这一点,但是在这里,制表符被标记为一个字符,而不是四个,我希望它是理想的。是否有一种更好的方式来获取列号而不必处理选项卡问题?

python tkinter
1个回答
3
投票

Tk文本窗口小部件的documentation -tabs选项提到2c的距离将是2厘米。该文档似乎没有说,但是它使用Tk_GetPixels函数将您的选项值转换为距离,并在其中指出以下类型:

<none> : The number specifies a distance in pixels.
c : The number specifies a distance in centimeters on the screen.
i : The number specifies a distance in inches on the screen.
m : The number specifies a distance in millimeters on the screen.
p : The number specifies a distance in printer's points (1/72 inch) on the screen.

如果要在字符中使用距离,则应使用font measure,该字符使用为文本窗口小部件定义的字体,并使用mn等合适的字符,前提是比例字体的字符宽度不同。 Tk文本小部件-tabs文档中提供了一个示例。

© www.soinside.com 2019 - 2024. All rights reserved.