proc wheelEvent { x y delta } { # Find out what's the widget we're on set act 0 set widget [winfo containing $x $y] if {$widget != ""} { # Make sure we've got a vertical scrollbar for this widget if {[catch "$widget cget -yscrollcommand" cmd]} return if {$cmd != ""} { # Find out the scrollbar widget we're using set scroller [lindex $cmd 0] # Make sure we act set act 1 } } if {$act == 1} { # Now we know we have to process the wheel mouse event set xy [$widget yview] set factor [expr [lindex $xy 1]-[lindex $xy 0]] # Make sure we activate the scrollbar's command set cmd "[$scroller cget -command] scroll [expr -int($delta/(120*$factor))] units" eval $cmd } } bind all <MouseWheel> "+wheelEvent %X %Y %D"