【发布时间】:2021-02-24 15:24:46
【问题描述】:
在这个简短的程序中,我想知道消息需要显示多少行。 问题是,与其回答我这里需要 3 行,它给了我 1。 为什么 ? 我尝试了关于这个主题的不同解决方案,但没有人在工作,每个人都有一些问题(这里没有计算行数)。
我在 Windows 10 上使用 Python 3.9.2
感谢您的帮助!!!
from tkinter import *
root = Tk()
text = Text(root, width = 12, height = 5, wrap = WORD)
text.insert(END, 'This is an example text.')
text.pack()
print(int(text.index('end-1c').split('.')[0]))
root.mainloop()
【问题讨论】:
-
@TheLizzard 是的,刚刚意识到
-
是的!我知道,因为我需要在主程序中的小部件文本大小之后调整这个数字
-
我用一个函数试过,用int转换的值不是pb,我无法计算wrap的次数:/
-
回答下面的作品。
标签: tkinter text count widget line