Updated 2016-08-30 23:50:46 by JOrge

GPS: I was curious the other day about who might be visiting my website, so I enabled the access_log for the Roxen webserver used by my ISP, and magically it began to grow. It grew so much that it became unmanageable, so I came up with this in ~10 minutes. It makes reading a huge file much easier...
 #Copyright 2003 George Peter Staplin
 #You may use/copy/modify this under the same terms as Tcl.
 proc gradify.text w {
  set colorList [list black_red black_green black_cyan black_orange]
  set end [lindex [split [$w index end] .] 0]
  set colorI 1
  for {set i 1} {$i < $end} {incr i} {
   $w tag add [lindex $colorList $colorI] $i.0 $i.end
   incr colorI
   if {$colorI > 3} {set colorI 0}
  $w tag configure black_red -background black -foreground red
  $w tag configure black_green -background black -foreground green
  $w tag configure black_cyan -background black -foreground cyan
  $w tag configure black_orange -background black -foreground orange 
 proc popup.selection.menu {w X Y} {
  set m .selpop
  destroy $m
  menu $m -tearoff 0
  $m add command -label Copy -command [list tk_textCopy $w]
  tk_popup $m $X $Y 

 proc main {argc argv} {
  scrollbar .yview -command [list .t yview]
  text .t -yscrollcommand [list .yview set]
  bind .t <ButtonPress-3> [list popup.selection.menu .t %X %Y]
  grid .yview -sticky ns -row 0 -column 0
  grid .t -sticky news -row 0 -column 1
  grid rowconfigure . 0 -weight 100
  grid columnconfigure . 1 -weight 100
  .t insert end [read [set fd [open [lindex $argv 0] r]]];
  close $fd 
  gradify.text .t
 main $::argc $::argv

how to launch it (from Windows/DOS in this case) and a screenshot:

See also:

I don't understand tk very well, so could someone explain, in the code above, what determines the size of the text box? I've a file that I want to monitor, but it is a fixed number of lines - each time the file is updated, the file is opened for write and the same number of lines are output.

However, the above program, which I thought might be useful to display this file, creates a box that has a lot more lines in it than necessary.

RS: If a text widget is created without -width or -height attributes, the defaults 80 resp. 24 apply (like on old monitors...) If you know your file has 17 lines, you can easily do
 text .t -height 17

or, if the widget is already there,
 .t configure -height 17

and, to suppress resizing by user,
 wm resizable .t 0 0

But text widgets are most often packed -fill both -expand 1 or gridded -sticky news, to give size control to the user.