使用该index
方法查找'end'的值,该值是缓冲区中最后一个字符之后的位置.
>>> text_widget.index('end') # returns line.column
'3.0'
>>> int(text_widget.index('end').split('.')[0]) - 1 # returns line count
2
Run Code Online (Sandbox Code Playgroud)
根据Bryan Oakley的评论更新:
>>> int(text_widget.index('end-1c').split('.')[0]) # returns line count
2
Run Code Online (Sandbox Code Playgroud)