首页 > 解决方案 > 用文本小部件编写的行间距

问题描述

如果有人非常了解 tkinter,他会得到我的确切要求。

我有一个代码,我试图查看该选项的影响,或者您可以说名为spacing2的文本小部件的关键字。我想知道为什么使用这个选项。

from tkinter import *
root = Tk()

txt = Text(root,spacing2 = 100)
txt.pack()

root.mainloop()

帮助我知道为什么这里使用了这个选项或名为spacing2 的关键字。

标签: pythontkinter

解决方案


根据文档(例如这里

此选项指定当逻辑换行时在显示的文本行之间添加多少额外的垂直空间。默认值为 0。

这是一个非常明显的例子:

from tkinter import Tk, Text
root = Tk()

txt = Text(root, spacing2=10, wrap='word', width=10)
txt.insert('1.0', 'This is a very long line that is wrapped.')
txt.pack()
txt2 = Text(root, wrap='word', width=10)
txt2.insert('1.0', 'This is a very long line that is wrapped.')
txt2.pack()

root.mainloop()

截屏


推荐阅读