Reputation:
I know how to use the built in method dump
, what I'm trying to do is filter the dump contents for just the text content. I came up with an ugly and inefficient one liner to do this:
list(filter(None, map(lambda line: line[1] if line[0] == "text" else None, self.text.dump(1.0, "end"))))
What's a better way to filter the dump list for just the text? Reason I'm doing this is to write the contents to a log file, if that's at all relevant. The one liner above works pretty well it gets all the text, new line characters, to be able to write the contents to the log file just looks ugly.
Upvotes: 0
Views: 422
Reputation: 385950
To get the text you use the get
method, giving it the starting and ending range of characters that you want. To get the whole text do:
self.text.get("1.0", "end-1c")
Note: "end-1c"
means "the last character, minus one character", which prevents you from getting the extra newline that tkinter adds.
Upvotes: 2