Member Avatar for masterofpuppets

hi everyone,
I am trying to design an assembler program with Python using Tkinter and so far it is going pretty good. I just have one question: Is there anyway to change the text color of just a selected text using a text area? What I mean is, you know how in python when you insert a comment the color of the comment is different than the color of the statements; same for function definitions etc. Instead of '#' I am using ';' for comments but I have no idea how to implement this.

I've googled it up but with no results. All that comes up is how to change the overall text color, i.e of the whole text area.

Any help is greatly appreciated :)
Thanks!

Member Avatar for masterofpuppets

Found a solution :)

from Tkinter import *

def onclick():
   pass

root = Tk()
text = Text(root)
text.insert(INSERT, "Hello.....")
text.insert(END, "Bye Bye.....")
text.pack()

text.tag_add("here", "1.0", "1.4")
text.tag_add("start", "1.8", "1.13")
text.tag_config("here", background="yellow", foreground="blue")
text.tag_config("start", background="black", foreground="green")
root.mainloop()

nice...:)

Member Avatar for masterofpuppets

Thanks a lot bro :)

It's really helpful.

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.