【问题标题】:TK text widget index not properly counting lines?TK 文本小部件索引未正确计算行数?
【发布时间】:2014-01-29 01:18:56
【问题描述】:

我尝试了下面的代码并使用 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()

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    它只计算物理行,而不是已经换行的行。你只插入了一行,所以它只计算一行。换行对行数没有影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      相关资源
      最近更新 更多