title: How to highlight a specific word in tkinter?
body: <p>I need to highlight a specific word in a text within a tkinter frame. In order to find the word, I put a balise like in html. So in a text like "hello i'm in the |house|" I want to highlight the word "house".</p>
  
  <p>My frame is defined like that:</p>
  
  <p><code>class FrameCodage(Frame):
        self.t2Codage = Text(self, height=20, width=50)</code> </p>
  
  <p>and I insert my text with this code: <code>fenetre.fCodage.t2Codage.insert(END, res)</code> , res being a variable containing my text.</p>
  
  <p>I saw this code on an other post: </p>
  
  <pre><code>class CustomText(tk.Text):
  '''A text widget with a new method, highlight_pattern()
  
  example:
  
  text = CustomText()
  text.tag_configure("red", foreground="#ff0000")
  text.highlight_pattern("this should be red", "red")
  
  The highlight_pattern method is a simplified python
  version of the tcl code at http://wiki.tcl.tk/3246
  '''
  def __init__(self, *args, **kwargs):
      tk.Text.__init__(self, *args, **kwargs)
  
  def highlight_pattern(self, pattern, tag, start="1.0", end="end",
                        regexp=False):
      '''Apply the given tag to all text that matches the given pattern
  
      If 'regexp' is set to True, pattern will be treated as a regular
      expression.
      '''
  
      start = self.index(start)
      end = self.index(end)
      self.mark_set("matchStart", start)
      self.mark_set("matchEnd", start)
      self.mark_set("searchLimit", end)
  
      count = tk.IntVar()
      while True:
          index = self.search(pattern, "matchEnd","searchLimit",
                              count=count, regexp=regexp)
          if index == "": break
          self.mark_set("matchStart", index)
          self.mark_set("matchEnd", "%s+%sc" % (index, count.get()))
          self.tag_add(tag, "matchStart", "matchEnd")
  </code></pre>
  
  <p>But they are few things that I don't understand: how can I apply this function to my case? When did I call this function? What's the pattern and the tag in my case? I'm a beginner in Tkinter so don't hesitate to explain to me this code, or another.</p>