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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.