我必须将文本小部件的标签大小设置为4个字符.当我做
textwidget.config(tabs =(“ 4c”,“ 8c”))我没有得到所需的结果.它的制表符很多,现在是4个字符.设置tabs属性时我做错什么了吗?另外,当我显示行号和列号时,可以通过获取插入物的索引来实现,但是在这里,制表符被标记为一个字符,而不是四个,我希望它是理想的.有没有一种更好的方法来获取列号而不必处理这种制表符问题?
解决方法:
Tk文本小部件-tabs选项的documentation提到2c的距离将是2厘米.该文档似乎没有说,但是它使用Tk_GetPixels函数将您的选项值转换为距离,并在其中指出以下类型:
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,该字符使用为文本窗口小部件定义的字体,并使用适当的字符(如m或n),因为比例字体的字符宽度不同. Tk文本小部件-tabs文档中提供了一个示例.
标签:tkinter,python
来源: https://codeday.me/bug/20191121/2048379.html