title: Tkinter Format Text on Entry
body: <h2>Formatting Text into a Time Format as the user Types</h2>
  
  <p>I'm trying to format text into the standard time format of <code>00:00:00</code> in a Tk.Entry textbox, as the user types in the numbers.</p>
  
  <p>I understand that Tkinter is not the easiest, nor best optimized framework to format text while the user types, but I've managed to get this far:</p>
  
  <pre><code>from Tkinter import *
  
  class Application(Frame):
      def __init__(self, master=None):
          Frame.__init__(self, master)
          self.pack()
          self.createWidgets()
  
  
      def createWidgets(self):
          sv = StringVar()
          sv.trace("w", lambda name, index, mode, sv=sv: self.entryUpdateEndHour(sv))
          endHourEntry = Entry(self, textvariable=sv)
          endHourEntry.pack()
  
      def entryUpdateEndHour(self, sv):
          global x
  
          x = sv.get()[0:2] + ':'
          y = x + sv.get()[3:5] + ':'
          z = y + sv.get()[6:8]
  
          sv.set(z)
  
  
  root = Tk() 
  app = Application(master=root) 
  app.mainloop()
  </code></pre>
  
  <p>This prints out exactly what I want (<code>12:45:67</code>), but the live formatting is bad. For example, in typing two numbers I get <code>12:::</code> in the textbox, and it skips every 3rd number I type in, since it replaces it with a <code>:</code>.</p>
  
  <p>I would be very grateful if someone has any work arounds or solutions to this answer. Thanks in advance.</p>