user6536489
user6536489

Reputation:

How to get the contents of last line in tkinter text widget (Python 3)

I am working on a virtual console, which would use the systems builtin commands and then do the action and display output results on next line in console. This is all working, but how do I get the contents of the last line, and only the last line in the tkinter text widget? Thanks in advance. I am working in python 3. I have treed using text.get(text.linestart, text.lineend) To no avail. Have these been deprecated? It spits out an error saying that AttributeError: 'Text' object has no attribute 'linestart'

Upvotes: 4

Views: 4787

Answers (3)

VED3V
VED3V

Reputation: 1

To get information from the last line you can use

text.get("end-1c linestart", "end-1c lineend")

Upvotes: 0

Tao
Tao

Reputation: 21

Test widget has a see(index) method. text.see(END) will scroll the text to the last line.

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 386342

You can apply modifiers to the text widget indicies, such as linestart and lineend as well as adding and subtracting characters. The index after the last character is "end".

Putting that all together, you can get the start of the last line with "end-1c linestart".

Upvotes: 3

Related Questions