so i was trying out tkinter Text widget.. and made a small code that highlights the word "print" in the text.. CODE:
from tkinter import *
def get(*arg):
print("Highlighting...")
text.tag_remove('found', '1.0', END)
s = "print"
if s:
idx = '1.0'
while 1:
idx = text.search(s, idx, nocase=1, stopindex=END)
if not idx: break
lastidx = '%s+%dc' % (idx, len(s))
text.tag_add('found', idx, lastidx)
idx = lastidx
text.see(idx) # Once found, the scrollbar automatically scrolls to the text
text.bind('<<Modified>>', get)
break
text.tag_config('found', foreground='green')
root = Tk()
text = Text(root)
text.grid()
root.bind('<<Modified>>', get)
root.mainloop()
In this, the root.bind('<<Modified>>', get)
works only once.
i checked it with the line print("Highlighting...")
it just worked once even when i enter thousands of characters..
Am i doing something wrong? or my approach is bad?
SPECS:
OS: Windows 7 SP1 (i will upgrade only to windows 11)
Python: Python 3.8.10
Arch: Intel x86