title: Tkinter - Python : Changing background color
body: <pre><code>[Person: Ahmet] is very handsome . He is working at [Organization: Zara] , their family live in [Location: Istanbul]
  
  
  Person: 1
  Location: 1
  Organization: 1
  </code></pre>
  
  <p>i have a text output like that and i show this in tkinter text .
  i want to change my background colors like that:</p>
  
  <pre><code>[Person: anyword] # yellow
  [Organization: anyword] #green
  [Location: anyword] #orange
  </code></pre>
  
  <p>How can i create a tag configuration ?</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import os
  import sys
  import os.path
  import io
  import subprocess as sub
  
  import Tkinter
  from Tkinter import *
  import csv
  import subprocess
  
  from tkFileDialog import *
  
  
  class App(object):
      def __init__(self, master):
          frame = Frame(master)
          frame.pack()
          self.text = Text()
      self.text1 = Text()
      self.text.pack()
      self.text1.pack()
  
          menu = Menu(master)
          root.config(menu=menu)
          # file menu
          filemenu = Menu(menu, tearoff=0)
          menu.add_cascade(label="Browse Text File", menu=filemenu)
          filemenu.add_command(label="New")
          filemenu.add_command(label="Open", command=self.file_open)
          filemenu.add_command(label="Save", command=self.file_save)        
          filemenu.add_separator()
          filemenu.add_command(label="Exit", command=self.do_exit)
  
      def file_open(self):
          """open a file to read"""
          # optional initial directory (default is current directory)
          initial_dir = "C:\Temp"
          # the filetype mask (default is all files)
          mask = \
          [("Text and Python files","*.txt"), 
          ("HTML files","*.htm"), 
          ("All files","*.*")]        
          fin = askopenfile(initialdir=initial_dir, filetypes=mask, mode='r')
          text = fin.read()
      proc = subprocess.Popen(['python', 'ner.py',  str(askopenfilename())], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
          if text != None:
              self.text.delete(0.0, END)
              self.text.insert(END,text)
          self.text1.delete(0.0, END)
          self.text1.insert(END,proc.communicate()[0])
  
  
  
      def file_save(self):
          """get a filename and save the text in the editor widget"""
          # default extension is optional, here will add .txt if missing
          fout = asksaveasfile(mode='w', defaultextension=".txt")
          text2save = str(self.text.get(0.0,END))
          fout.write(text2save)
          fout.close()
  
      def do_exit(self):
          root.destroy()
  
  
  
  root = Tk()
  root.title("Named Entity Recognizer (TR)")
  app = App(root)
  root.mainloop()
  </code></pre>
  
  <p>First i show the original text and second i show the edited text which found ner types. I know it works with tag configure but how can i add the words inside the brackets. Thanks for helping.</p>
  
  <p>text.tag_config("[Person: ??]", background="yellow", foreground="red")</p>