Home > Software engineering >  Insertation Cursor (INSERT) trouble with scrolled text in Tkinter
Insertation Cursor (INSERT) trouble with scrolled text in Tkinter

Time:07-26

I'm having a problem with scrolled text in tkinter with the insert cursor.

I'm making a code editor (like notepad but with features), I was making auto bracket close but and it works, but the INSERT cursor which is the line when you are typing (shows where) is one character in front of the closing bracket not inside of it. I could not find a way to move it back,

Entry widgets have the method icursor (insertcursor) but scrolled text does not.

CODE: st = the scrolled text widget

#bracket open and close

    def bo(event):
      self.st.insert(END, ")")
      
      #code to make insert cursor move back

      return

    
    self.st.bind('<KeyRelease-(>', bo)

Thank you. Have a good day!

CodePudding user response:

You can use self.st.mark_set('insert', 'insert-1c') to move the insertion cursor one character back:

def bo(event):
    self.st.insert('insert', ')')
    self.st.mark_set('insert', 'insert-1c')
  • Related