progressbars

It's traditional--perhaps dysfunctionally so--for Tk-ers to code their own progressbars, often on the model found in the "Bag of Tk algorithms". It's certainly true that Tk makes it easy. Tk 8.5, Tile, mkWidgets and BWidget build in progressbar widgets.


Also a nice and simple progress bar is the one by DKF at: http://www.man.ac.uk/~zzcgudf/tcl/mwidx.html#progress It is also able to display the percentage along with the filled rectangular... - George


Practical development of progressbars often involves questions of how to "keep a GUI alive during a long calculation".


RS likes this one, overloading widgets, where color changes from red via yellow to green, and which can also be used in "piechart" fashion:

WikiDbImage progress.jpg

proc progressbar {w args} {
    array set opt {
        -width 256 -height 16 -relief sunken -borderwidth 1 -style bar
    }
    array set opt $args
    set style $opt(-style)
    unset opt(-style)  ;# don't let the canvas get this
    eval canvas $w [array get opt]
    set h [$w cget -height]
    switch -- $style {
        bar {
            $w create rect 1 1 1 [expr {$h-1}] -fill CornflowerBlue \
                -tags {bar status}
        }
        circle {
            $w create arc  1 1 [expr {$h-1}] [expr {$h-1}] -start 90 \
             -fill CornflowerBlue -tags {arc status} -extent 0
        }
    }
    $w create text [expr [$w cget -width] / 2] [expr $h / 2] \
        -text "0 %" -tags txt
    rename $w _$w
    proc $w {args} {
        set w [lindex [info level 0] 0]
        if {[lindex $args 0] == "set"} {
            set n [lindex $args 1]
            set h [winfo height $w]
            set width [winfo width $w]
            set color [color:rgb $n]
            $w itemconf txt -text "$n %"
            $w coords txt [expr $width / 2] [expr $h / 2]
            $w coords bar 1 1 [expr $n * $width / 100] [expr $h - 1]
            $w itemconf status -fill $color -outline $color
            $w itemconf arc -extent [expr $n*-3.599]
        } else {
            eval _$w $args 
        }
    }
    set w
}

proc color:rgb {n} {
    # map 0..100 to a red-yellow-green sequence
    set n     [expr {$n < 0? 0: $n > 100? 100: $n}]
    set red   [expr {$n > 75? 60 - ($n * 15 / 25) : 15}]
    set green [expr {$n < 50? $n * 15 / 50 : 15}]
    format    "#%01x%01x0" $red $green
}

#----- Test:
if {[file tail [info script]]==[file tail $argv0]} {
    progressbar .1
    progressbar .2 -style circle -height 50 -width 50
    pack .1 .2
    
    proc test {} {
        for {set i 0} {$i<=10000} {incr i 100} {
             after $i .1 set [expr $i/100]
             after $i .2 set [expr $i/100]
        }
    }
    test
    bind . <1> test
}

A variation: An analogue countdown clock-face


Also see "poor man's progressbar" and "Simple Download Progress Widget".


A progressbar for the console is Progress.

Googie - There is also console progressbar in VT100 terminal library for TCL examples.


text mode (terminal) progress bar / progressbar


060818 a(Mapped)ProgressBar is a nice implementation