[英]TK text widget index not properly counting lines?
我嘗試了下面的代碼,並使用index方法嘗試獲取文本框中包含的文本行數,但我不斷返回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()
它僅計算物理線,而不計算纏繞的線。 您只插入了一行,所以只算了一行。 包裝對行數沒有影響。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.