TK change color of line in Text widget

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arepi
    New Member
    • Sep 2008
    • 62

    TK change color of line in Text widget

    Hi!

    Its possible, to change the color of characters line by line in a Text widgets?
    See:
    "characters of line1" #color of this line is red
    "characters of line2" #color of this line is green
    ....


    Thanks!
  • aurekha
    New Member
    • Sep 2007
    • 34

    #2
    Use "foreground " option for text widget with 'configure' method..

    Comment

    • nithinpes
      Recognized Expert Contributor
      • Dec 2007
      • 410

      #3
      Originally posted by aurekha
      Use "foreground " option for text widget with 'configure' method..
      Using configure() method with '-foreground' option, you can set the text color for entire text box. I don't think that can be used to set color for each line of data in textbox.

      Comment

      • nithinpes
        Recognized Expert Contributor
        • Dec 2007
        • 410

        #4
        Originally posted by nithinpes
        Using configure() method with '-foreground' option, you can set the text color for entire text box. I don't think that can be used to set color for each line of data in textbox.
        This can be done. Try the following approach:
        Code:
        $tx->tag(qw/configure color1 -foreground red/);
        $tx->tag(qw/configure color2 -foreground green/);
        $tx->tag(qw/configure color3 -foreground blue/);
        $tx->tag(qw/configure color4 -foreground black/);
        
        $tx->insert('insert', "characters of line1\n", 'color1');
        $tx->insert('insert',"characters of line2\n", 'color2');
        $tx->insert('insert',"characters of line3\n", 'color3');
        $tx->insert('insert',"characters of line4\n", 'color4');

        Comment

        Working...