I need to consequently find each matching word add scroll to it in the text box with a button click. This function only finds the first matching word. How can I feed the updated index to a function that is bound to the button?
def find(idx='1.0'):
text.tag_remove('found', idx, END)
s = edit.get()
if s:
idx = text.search(s, idx, nocase=1,
stopindex=END)
if not idx:
return None
foundidx = '%s+%dc' % (idx, len(s))
text.tag_add('found', idx, foundidx)
text.see(foundidx)
text.tag_config('found', foreground='red')
edit.focus_set()
return foundidx
To achive this you need a
Text
widget and a root that display via widget a example text. I did it with this:after this I followed the instructions of the link out of the comments. And extended it by saveing the positions and the index.
At least I used the
Text.see
method to jump to the points of my posis list:I know this code can be improved by a lot, but it should show the priciple and I used to code it self explanatory. But if there are open questions, let me know and I improve this answer.