Tags: color, didnt, example, programming, python, sequence, text, theascii, widget

Color text in Text widget

On Programmer » Python

1,693 words with 1 Comments; publish: Mon, 12 May 2008 00:03:00 GMT; (200139.65, « »)

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 <Redred <Red>, but this is <Blueblue <Blue>

Thanks.

Santosh.

Tutor maillist - Tutor (AT) python (DOT) org

All Comments

Leave a comment...

  • 1 Comments
    • Thanks.

      Its works very well.

      Santosh.

      8/1/05, Jorge Louis de Castro <jobauk (AT) hotmail (DOT) comwrote:

      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

      jorge

      >From: sunny sunny <sunny.tired (AT) gmail (DOT) com>

      >To: tutor (AT) python (DOT) 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 <Redred <Red>, but this is <Blueblue <Blue>

      >

      >Thanks.

      >Santosh.

      >

      >Tutor maillist - Tutor (AT) python (DOT) org

      >

      Tutor maillist - Tutor (AT) python (DOT) org

      #1; Mon, 12 May 2008 00:05:00 GMT