How to add tag to a new line in tkinter Text? How to add tag to a new line in tkinter Text? tkinter tkinter

How to add tag to a new line in tkinter Text?


Every index you use to add highlighting begins with "1.", so it's always only going to highlight the first sentence. For example, if the line is 36 characters long, an index of "1.100" will be treated exactly the same as "1.36".

Tkinter can compute new indexes by adding to an existing index, so instead of "1.52" (for a line that is 36 characters long) you want "1.0+52chars". For example:

def concord(self, event):    ...    for word_found in word_concord:        start = self.string_text.index("1.0+%d chars" % word_found.start())        end = self.string_text.index("1.0+%d chars" % word_found.end())        self.string_text.tag_add('color', start, end)    ...