Version 1 of Resizing fonts on window resize

Updated 2006-01-30 17:43:15

schlenk, 19. July 2005: Answering a question on self-tcl.de [L1 ] i came up with this little demo. It shows how to dynamically resize a label with some text, when the window is resized:

 package require Tk
 package require math::interpolate

 proc createInterpolationTable {win font text} {
   set max [winfo vrootwidth $win]
   set oldsize [font configure $font -size]
   set xval [list]
   set yval [list]
   set x 0
   set size 2
   while {$x < $max} {
      font configure $font -size $size
      set x [font measure $font $text]
      lappend xval $x
      lappend yval $size
      incr size 4
   }
  font configure $font -size $oldsize
  return [list $xval $yval]
 }

 proc adjustFont {font width ipt} {
   set newSize [lindex [math::interpolate::neville [lindex $ipt 0] [lindex $ipt 1] $width] 0]
   font configure $font -size [expr {int($newSize)}]
 }

 proc configureBinding {font ipt win width heigth} {
    adjustFont $font $width $ipt
 }

 font create title -family Verdana -size 10
 toplevel .test
 set txt "Some Titel"
 set ipt [createInterpolationTable .test title $txt]
 label .test.l -text $txt -font title
 pack .test.l -expand 1 -fill both
 bind .test.l <Configure> [list configureBinding title $ipt %W %w %h] 

See also font Category GUI | Category Example