title: Tkinter and reading current line from Text widget
body: <p>I have an issue where I try to read the current line as I type...Problem is the output I get is not really what it should be...</p>
  
  <p>Below is the structure of the program for now.</p>
  
  <p>"key_press" function is the section where the problem relies.</p>
  
  <pre><code>from tkinter import *
  import keyword
  
  ### TEXT EDITOR WIDGET
  class TextEditor(Text):
  
  # TAGS
  tags = {"int": "red"}
  
  ### Init
  def __init__(self, root):
      Text.__init__(self, root)
      self.bind("&lt;Key&gt;", self.key_press)
      self.bind("&lt;Button-1&gt;", self.key_press)
  
  ### Add tags
  def congif_tags(self):
  
      for tag, val in self.tags.items():
          self.tag_config(tag, foreground=val)
  
  ### Remove tags
  def remove_tags(self, start, end):
  
      for tag in self.tags.keys():
          self.tag_remove(tag, start, end)
  
  ### On keyboard press event
  def key_press(self, key):
      current_line = self.index(INSERT)
      current_line = current_line.split(".")
      current_line = current_line[0]
  
      line_break = 0
  
      line_text = ""
  
      char = self.get("%s.%d" % (current_line, line_break ))
  
      while char != "\n":
          line_break += 1
          char = self.get("%s.%d" % (current_line, line_break))
          line_text += char
  
      print(line_text)
  </code></pre>