title: Tkinter adding line number to text widget
body: <p>Trying to learn tkinter and python. I want to display line number for the Text widget in an adjacent frame</p>
  
  <pre><code>from Tkinter import *
  root = Tk()
  txt = Text(root)
  txt.pack(expand=YES, fill=BOTH)
  frame= Frame(root, width=25)
  #
  
  frame.pack(expand=NO, fill=Y, side=LEFT)
  root.mainloop()
  </code></pre>
  
  <p>I have seen an example on a site called unpythonic but its assumes that line height of txt is 6 pixels. </p>
  
  <p>I am trying something like this:</p>
  
  <p>1) Binding Any-KeyPress event to a function that returns the line on which the keypress occurs:</p>
  
  <pre><code>textPad.bind("&lt;Any-KeyPress&gt;", linenumber)
  
  
  def linenumber(event=None):
      line, column = textPad.index('end').split('.')
      #creating line number toolbar
      try:
         linelabel.pack_forget()
         linelabel.destroy()
         lnbar.pack_forget()
         lnbar.destroy()
      except:
        pass
     lnbar = Frame(root,  width=25)
     for i in range(0, len(line)):
        linelabel= Label(lnbar, text=i)
        linelabel.pack(side=LEFT)
        lnbar.pack(expand=NO, fill=X, side=LEFT)
  </code></pre>
  
  <p>Unfortunately this is giving some weird numbers on the frame.
  Is there a simpler solution?
  How to approach this?</p>