Hung Truong Hung Truong - 2 months ago 13x
Python Question

Tkinter Text widget : Fetching Cursor Selection

I have a text widget, and I have the text

this is some random text

With the keyboard cursor in the word "
". How can I get the start and end index of the cursor selection.

Thanks in advance!


You can get the index of the start of the word by applying the modifier "wordstart" to an index. To get the end of the word, use "wordend".

For example:

start = text.index("insert wordstart")
end = text.index("insert wordend")