Hi, so in order to make my problem more clear, I shall just make a simple example of what I am trying to do. I will start with a little code:

from Tkinter import *

master = Tk()

msgbox = Text(master)
msgbox.pack()

mytext = raw_input("> ")
msgbox.insert(END, mytext)

master.mainloop()

Now, say I enter the string "foo just ran down the street and met his friend bar. foo was very happy" when I am prompted by "raw_input". What I would like to do is tag all occurrences of "foo" and color them red. How would I go about doing this?

Thanks in advance.

Sorry, I finally figured this out myself. If anybody is curious:

msgbox = Text(master)
msgbox.tag_config("myfootag", foreground="#66FFFF")

mytext = raw_input("> ")
if "foo" in mytext:
      parts = mytext.split("foo")
      msgbox.insert(END, parts[0])
      msgbox.insert(END, "foo", ("myfootag"))
      msgbox.insert(END, parts[1]+"\n")

IMPORTANT NOTE: This code assumes that you will only have one instance of "foo" in your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.