I am using Tkinter in python to display the output in a text window. I found that with \'get\' function I can retrieve the text content from this window. But I have text portion
There is no support for what you want. You can call the .dump()
method which will return information including both the text and the tags. However, this data is not in a standard format and there's no support for loading the data back in. It's possible to write software to load it back in, but you have to do all the work yourself.
The best description of what is returned is from the tcl/tk man pages. It states in part:
pathName dump ?switches? index1 ?index2?
Return the contents of the text widget from index1 up to, but not including index2, including the text and information about marks, tags, and embedded windows. If index2 is not specified, then it defaults to one character past index1. The information is returned in the following format:
key1 value1 index1 key2 value2 index2 ...
The possible key values are text, mark, tagon, tagoff, image, and window. The corresponding value is the text, mark name, tag name, image name, or window name. The index information is the index of the start of the text, mark, tag transition, image or window.
N.B. the documentation is for the tcl language. In tkinter you would call the method as widget.dump(...)
, and it returns a tuple.