TK文本小部件索引没有正确计数行?

时间:2014-01-29 01:18:57

标签: python tkinter

我已经尝试了下面的代码,并使用索引方法尝试获取文本框中包含的文本行数,但我不断返回1行而不是文本框中存在的2行。

from Tkinter import *

master = Tk()

text = Text(master,width=40,height=50,wrap='word')
text.insert('1.0', 'Here is my text to insert, next i want to test the word wrap')
text.tag_add('font', '1.0', 'end')
text.tag_configure('font', font='arial 12', relief='raised')
text.pack()
print int(text.index('end-1c').split('.')[0])

mainloop()

1 个答案:

答案 0 :(得分:1)

它只计算物理线,而不是包裹的线。你只插了一行,所以它只计算一行。环绕对行数没有影响。