code: def restore_position(self):
          
          # restore text cursor position:
          self.mark_set(tkinter.INSERT, self.old_text_pos)
          # restore scroll position:
          self.yview_moveto(self.old_first)
docs: restore cursor and scroll position