Version 1 of text line coloring

Updated 2006-01-04 16:59:52 by suchenwi

Richard Suchenwirth 2006-01-04 - Here's a cute little code snipped that I just have to share. If you display lines in a text widget, you might want to have every second in another background color:

http://mini.net/files/colorlines.jpg

Here's all it takes (computing the tag name from the line number modulo 2 - "1" is colorful, "0" is ignored):

 package require Tk

 pack [text .t]
 .t tag configure 1 -background lightblue

 set line -1
 foreach item {these are some words for testing} {
     .t insert end $item\n [expr [incr line]%2]
 }

Category Example | Arts and crafts of Tcl-Tk programming