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 :)

Recommended Answers

Also take a look at:
for a mildly more general version.

Jump to Post

All 3 Replies

Found a solution :)

from Tkinter import *

def onclick():

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

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")


Thanks a lot bro :)

It's really helpful.

Be a part of the DaniWeb community

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