Using re.finditer won't return all matches Using re.finditer won't return all matches tkinter tkinter

Using re.finditer won't return all matches


You are using a float for the text widget indexes. The indexes are not floats, they are strings of the form line.column. You are then making the odd choice of rounding the index up or down.

Let's take a look at "NOYDIR" as an example, since that's one you claim it isn't finding. With just a single print statement you'll see that it's finding NOYDIR, but the indexes it is computing are 14.32 as the start, and 14.4 as the end. Because the end index is before the start index (character 4 is before character 32), tkinter won't highlight that word.

Why is the second index 14.4? It is because e.start() returns 40. You convert that to a float by appending a "." and the value to the row, yielding "1.40". You then convert it to a float, which converts "1.40" to "1.4". This is exactly why you should not treat text widget indexes as floats. The index is a string in the form of line.column. When you convert it to a float, the value "14.40" is indentical to "14.4", but to the text widget "14.40" and "14.4" are very different things.


I found in tkinter documentation that index should bepassed as a string, containing row and column number,separated with a dot.

So it looks weird to me that you change the indices to float and then round them.

I think, these instructions should be dropped.