Hung Truong Hung Truong - 1 year ago 131
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!

Answer Source

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")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download