Version 1 of poor man's progressbar

Updated 2003-08-14 06:16:13

Brett Schwarz So, you want a progressbar, but don't want to load an external package (ok, I am digging here :) ).

Well, you can get a basic progressbar by just re-using the scale widget. Here is an example:


 scale .sc \
    -orient horizontal \
    -sliderrelief flat \
    -sliderlength 0 \
    -troughcolor #AAAAAA \
    -showvalue 0 \
    -label 0

Notice the relief as flat. You could use another relief, but the results aren't as good. We set sliderlength to 0, so initially, nothing is shown. We will take advantage of the sliderlength to actually animate the progressbar.

Here is a proc that could be used to move the progressbar:


 proc setpb {value} {
    .sc configure \
        -sliderlength [expr {$value - 3}] \
        -label $value

    return
 }

the $value - 3 is just a fudge factor to make it look nicer when display (on Linux running 8.4.4). So, an example of the usage would be:


 for {set i 5} {$i <= 80} {incr i 5} {
        setpb $i
        update idletasks
        after 50
 }

And this is what it would look like:

http://bschwarz.com/scale_gauge.png

[ Category Example | Category GUI | Category Widget ]