Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

colors for line of a text widget

Status
Not open for further replies.

sl1200mk2

Technical User
Jun 7, 2005
39
FR
hi

how to give a color red for a line of a textwidget selected with

[lindex [split $k \n] $spin]

where $k is the text and $spin is the selected line

??
thanks
nico
 
You can set attributes on different regions of a text widget (including but not restricted to lines) using tags. To set a tag, you need something like:
<text widget path> tag add <tag name> <start index> <end index>. In your case I gather the text widget path is $k. Now let's say you had line number X that you wanted to set a color for. That would be:
$k tag add <tag name> X.0 X.end, to get the whole line. X isn't the same as $spin because the lines are numbered from 1, not 0. Now you would have a tag specified that corresponded to that line. You use the tag configure statement to change/set the color:
$k tag configure <tag name> -background red.

_________________
Bob Rashkin
rrashkin@csc.com
 
hi bong

it works, but with 1.0 1.end , the first line is red
with 2.0 2.end , both firsst and second line are red

should i add another line like
$k tag add <tag name> (X-1).0 (X-1).end
$k tag configure <tag name> -background white

++
nico
 
When I do:
% pack [text .t]
% .t tag add t2 2.0 2.end
% .t tag configure t2 -background red

I get only the second line's background to change. If your problem is to reset one line previously changed when you change another, I'd use resetting the whole text:
$k configure -background white
or whatever attribute you are changing with the tags.

_________________
Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top