How to get the current cursor position for a text widget

I am using an onscreen keyboard to enter data for the tkinter gui. I was able to use the input field to enter, edit data using the on-screen keyboard, like getting the current cursor position and line length.

temp = self.entry_label.get()
length_string=len(temp)
cursor_position = self.entry_label.index(INSERT)

      

But I want to do the same for the Text widget. I can get the text for the text widget using the method get()

and its length, but I cannot get the current position of the mouse cursor.

temp=self.new_text.get(1.0, END)
cursor_position = self.new_text.index(INSERT)

      

Sincerely this works and I can add a character to that position, but after adding the character cursor, it goes back to its original position, i.e. the last character

+3


source to share


1 answer


maybe It works? Else maybe text_widget.index(Tkinter.INSERT)

is what should work.



+1


source







All Articles