TextZoom -Using mousewheel scrolling events to interactively re-size text widget content

WJG 2006-06-05: After staring and pondering at text documents for hours on end things look a little, well lost. Varying the font size not only can make the more 'bunched-up' words clearer and also helps the old brain to get back into action. This is especially the case if one uses non-roman text such as Chinese where complex characters at smaller text size can be bothersome. I guess that someone has already done something like this already on the wiki (RS: Indeed: see Font resizing via mousewheel), but here goes. Some future changes might include changing the fonts sizes within tags.

# TextZoom .tcl

proc TextZoom {w} {
    # only for text widgets
    if {[winfo class $w]!="Text"} {return -1}
    
    bind $w <Control-MouseWheel> {
        set fsize [lindex [%W cget -font] 1]

        if { %D >= 0 } {
            incr fsize 2
        } else {
            incr fsize -2
        }

        set fnt "\{[lindex [%W cget -font] 0 ] $fsize\}"
        
        eval %W configure -font $fnt
    }
}


console show
pack [text .txt -font {Arial 24} ] -fill both 
.txt insert end Apple
wm geometry . =500x250
TextZoom .txt