# Description: makes all scrollbars disappear when not needed proc scrollbar {args} { eval _scrollbar $args autoscroll [lindex $args 0] } bind Autoscroll [namespace code [list destroyed %W]] proc autoscroll { w } { rename $w [namespace current]::renamed$w interp alias {} ::$w {} [namespace current]::widgetCommand $w bindtags $w [linsert [bindtags $w] 1 Autoscroll] eval [list ::$w set] [renamed$w get] return $w } proc unautoscroll { w } { if { [info commands [namespace current]::renamed$w] != "" } { variable grid rename ::$w {} rename [namespace current]::renamed$w ::$w if { [set i [lsearch -exact [bindtags $w] Autoscroll]] > -1 } { bindtags $w [lreplace [bindtags $w] $i $i] } if { [info exists grid($w)] } { eval [join $grid($w) \;] unset grid($w) } } } proc widgetCommand { w command args } { variable grid if { $command == "set" } { foreach { min max } $args {} if { $min <= 0 && $max >= 1 } { switch -exact -- [winfo manager $w] { grid { lappend grid($w) "[list grid $w] [grid info $w]" grid forget $w } pack { foreach x [pack slaves [winfo parent $w]] { lappend grid($w) "[list pack $x] [pack info $x]" } pack forget $w } } } elseif { [info exists grid($w)] } { eval [join $grid($w) \;] unset grid($w) } } return [eval [list renamed$w $command] $args] } proc destroyed { w } { variable grid catch { unset grid($w) } rename ::$w {} } proc unload {} { rename ::scrollbar {} rename [namespace current]::_scrollbar ::scrollbar foreach x [info commands renamed*] {unautoscroll [string range $x 7 end]} } proc iterate {w} { foreach c [winfo children $w] { if {[winfo class $c] == "Scrollbar"} {autoscroll $c} if {[winfo children $c] != ""} {iterate $c} } } if {[info commands _scrollbar] == ""} { rename ::scrollbar [namespace current]::_scrollbar namespace export scrollbar namespace eval :: "namespace import [namespace current]::*" iterate . }