Is there a way to get the start and end index of the visible text in a tkinter text widget?
"myTextWidget.index(CURRENT)" is not what I am looking for, since it only gives me the index of the cursor position.
I want to build a program which search for a word and format all of the word found. However, if there are many words, it takes a lot of time to format all the words. Thus, I only want to format the words which are visible to the user. If the user scrolls up or down, it will again update only the visible text.
I found this post, but this is not what I am looking for: Visible lines in Tkinter text widget
I have included some example code. However, not even this works perfectly. The index of the cursor does not update with all key releases.
from tkinter import *
from tkinter import scrolledtext
def update_visible_text_index(e):
message = "Index of current visible text: " + myText.index(CURRENT)
# "myText.index(CURRENT)" should be replaced with something else
myLabel.config(text = message)
root = Tk()
root.title("My title")
root.geometry("400x400")
myLabel = Label(root, text="Scroll up and down", justify="center")
myLabel.pack()
myText = scrolledtext.ScrolledText(root, wrap=WORD)
myText.pack()
myText.insert('insert', testtext)
myText.bind("<KeyRelease>", update_visible_text_index)
root.mainloop()