title: How to change cursor position in Python tkinter Entry widget at every inserted and deleted values
body: <p>I have one Entry field and popup Keypad window.Whenever user clicked on entry field it accept input through Keypad.<strong>One of the problem which I faced it whenever I am reading current cursor position while entering user input it always showing cursor position at 'zero' and also user is not seeing any cursor in entry field while entering input through Keypad.</strong></p>
  
  <p>Code:</p>
  
  <pre><code>from tkinter import *
  from tkinter import simpledialog
  
  class Gui(Toplevel):
      def __init__(self, parent,*args):
          Toplevel.__init__(self, parent)
          self.title('User input window')
          self.geometry('450x350')
          self.EntryVar=StringVar()
          self.label = Label(self, text='User Input:', width=15, background='white', justify=CENTER,
                                    font='-weight bold')
          self.entry = Entry(self, width=15, background='white', textvariable=self.EntryVar,
                                    font='-weight bold')
          self.label.grid(row=2,padx=10, pady=5, column=0, sticky='E')
          self.entry.grid(row=2,padx=10, pady=5, column=1, sticky='E')
          self.entry.bind('&lt;FocusIn&gt;', self.keypad_popup)
  
      def keypad_popup(self,event):
          new = numPad(self, event.widget)
  
  class numPad(simpledialog.Dialog):
      def __init__(self, parent, *args):
          self.focus = args[0]
          self.parent = parent
          self.top = Toplevel(parent)
          self.top.title('Keypad')
          self.top.grab_set()
          self.createWidgets()
  
      def createWidgets(self):
          btn_list = ['6', '1', '2', '3', '0','C', 'D']
          r = 1
          c = 0
          n = 0
          btn = []
          for label in btn_list:
              cmd = lambda x=label: self.click(x)
              button = Button(self.top, text=label, width=10, height=5, command=cmd)
              btn.append(button)
              btn[-1].grid(row=r, column=c)
              n += 1
              c += 1
              if c == 3:
                 c = 0
                 r += 1
  
      def click(self, label):
          if label == 'D' and self.focus == self.parent.entry:
              currentText = self.parent.EntryVar.get()
              self.parent.EntryVar.set(currentText[:-1])
  
          elif label == 'C':
              self.top.destroy()
              self.top.master.focus()
  
          elif self.focus == self.parent.entry:
              currentText = self.parent.entry.get()
              self.parent.EntryVar.set(currentText + label)
              print('Cursor position:', self.parent.entry.index(INSERT))
  
  
  if __name__ == '__main__':
      root = Tk()
      root.title('root window')
      root.geometry("150x150")
      app = Gui(root)
      root.mainloop()
  </code></pre>