[Tutor] Color text in Text widget

Jorge Louis de Castro jobauk at hotmail.com
Mon Aug 1 22:12:53 CEST 2005

I found a way to do it but I'm not sure it is the cleanest. Maybe someone 
else on this list can offer a better solution.

I use the text's configuration to define tags that I apply to sections of 
the text. For example:

txtBox = Text(self, width=80, height=20)
# configuration for red
txtBox.tag_config("r", foreground="red")
# configuration for blue
txtBox.tag_config("b", foreground="blue")

txtBox.insert(END,"I am red ", "r")
txtBox.insert(END,"and I am blue\n", "b")

Hope that helps

>From: sunny sunny <sunny.tired at gmail.com>
>To: tutor at python.org
>Subject: [Tutor] Color text in Text widget
>Date: Mon, 1 Aug 2005 15:35:52 -0400
>Hi all,
>How do I add color to the text in the Text widget? I tried using the
>ASCII sequence but it didnt work.
>For example, I want to add:
>  This is <Red> red <Red>, but this is <Blue> blue <Blue>
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list