Search code examples
pythontkinterwidgettags

ways to tag characters in tkinter text widget


Is there an alternative way to index characters in text other than the one in the example below?

text.tag_add('highlightline', '1.1', '1.2')

For example, it would be useful to index them as if they were in a list or a 2D matrix. Where each row in the text corresponds to a row in the matrix and each cell of the matrix contains one character.


Solution

  • You can only use the line.char format for indexing the contents, along with a few variation (eg: “end”, @x,y) and modifiers like wordstart, wordstart, wordend, etc.

    For the full definitive and complete definition of what is allowed, see the indicies section of the official tk text widget documentation.