ttk::progressbar

Ttk's progressbar widget.

https://www.tcl-lang.org/man/tcl8.5/TkCmd/ttk_progressbar.htm

  TIP 442: text label

RZ To put text inside the progressbar and add -justify to ttk::button you can apply the following patch:

diff -ruN tk8.6.6ORI//generic/ttk/ttkButton.c tk8.6/generic/ttk/ttkButton.c
--- tk8.6.6ORI//generic/ttk/ttkButton.c        2016-07-22 07:11:20 +0000
+++ tk8.6/generic/ttk/ttkButton.c        2017-02-08 08:15:22 +0000
@@ -23,6 +23,7 @@
      * Text element resources:
      */
     Tcl_Obj *textObj;
+    Tcl_Obj *justifyObj;
     Tcl_Obj *textVariableObj;
     Tcl_Obj *underlineObj;
     Tcl_Obj *widthObj;
@@ -56,6 +57,9 @@
 
 static Tk_OptionSpec BaseOptionSpecs =
 {
+    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
+        "left", Tk_Offset(Base,base.justifyObj), -1,
+        TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
     {TK_OPTION_STRING, "-text", "text", "Text", "",
         Tk_Offset(Base,base.textObj), -1,
         0,0,GEOMETRY_CHANGED },
diff -ruN tk8.6.6ORI//generic/ttk/ttkProgress.c tk8.6/generic/ttk/ttkProgress.c
--- tk8.6.6ORI//generic/ttk/ttkProgress.c        2016-07-22 07:11:20 +0000
+++ tk8.6/generic/ttk/ttkProgress.c        2016-08-18 07:43:10 +0000
@@ -31,6 +31,13 @@
     Tcl_Obj         *valueObj;
     Tcl_Obj         *phaseObj;
 
+    Tcl_Obj *textObj;
+    Tcl_Obj *fontObj;
+    Tcl_Obj *foregroundObj;
+    Tcl_Obj *anchorObj;
+    Tcl_Obj *justifyObj;
+    Tcl_Obj *wrapLengthObj;
+
     int         mode;
     Ttk_TraceHandle *variableTrace;        /* Trace handle for -variable option */
     int         period;                        /* Animation period */
@@ -46,6 +53,24 @@
 
 static Tk_OptionSpec ProgressbarOptionSpecs =
 {
+    {TK_OPTION_STRING, "-text", "text", "Text", "",
+        Tk_Offset(Progressbar,progress.textObj), -1,
+        0,0,GEOMETRY_CHANGED },
+    {TK_OPTION_FONT, "-font", "font", "Font",
+        DEFAULT_FONT, Tk_Offset(Progressbar,progress.fontObj), -1,
+        TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
+    {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor",
+        "black", Tk_Offset(Progressbar,progress.foregroundObj), -1,
+        TK_OPTION_NULL_OK,0,0 },
+    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
+        "w", Tk_Offset(Progressbar,progress.anchorObj), -1,
+        TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED},
+    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
+        "left", Tk_Offset(Progressbar,progress.justifyObj), -1,
+        TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
+    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
+        "0", Tk_Offset(Progressbar, progress.wrapLengthObj), -1,
+        TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED},
     {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
         "horizontal", Tk_Offset(Progressbar,progress.orientObj), -1,
         0, (ClientData)ttkOrientStrings, STYLE_CHANGED },
@@ -522,7 +547,8 @@
 
 TTK_BEGIN_LAYOUT(HorizontalProgressbarLayout)
     TTK_GROUP("Horizontal.Progressbar.trough", TTK_FILL_BOTH,
-        TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y))
+        TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y)
+        TTK_NODE("Horizontal.Progressbar.text", TTK_PACK_LEFT))
 TTK_END_LAYOUT
 
 /*
diff -ruN tk8.6.6ORI//library/ttk/vistaTheme.tcl tk8.6/library/ttk/vistaTheme.tcl
--- tk8.6.6ORI//library/ttk/vistaTheme.tcl        2016-07-22 07:11:20 +0000
+++ tk8.6/library/ttk/vistaTheme.tcl        2016-02-16 16:17:13 +0000
@@ -182,6 +182,7 @@
         ttk::style layout Horizontal.TProgressbar {
             Horizontal.Progressbar.trough -sticky nswe -children {
                 Horizontal.Progressbar.pbar -side left -sticky ns
+                Horizontal.Progressbar.text -sticky nesw
             }
         }
         ttk::style element create Vertical.Progressbar.pbar vsapi \

  Bar color

D. McC 2008 Mar 26: Can anyone here provide a quick tip on how to change the foreground color of the progressbar from the blah blue-gray default to a color of the programmer's choice?

MG I'm not 100% sure if this is the right way, but it seems to work for me when using the "alt" theme.

  ttk::style configure TProgressbar -background $color

ttk::style

---

HaO 2011-05-23 Thread on clt 'How to change ttk::progressbar color? ' about bar color in vista.

Native Themes may not follow options that other themes have

(Kevin Walzer): On Windows and OS X, some ttk widget options cannot be configured because they are controlled by the underlying native theme engine. Progress bar colors cannot be changed on the Mac/Aqua, and I believe the same is true for Windows.

Windows Vista Widgets have a state which changes the color

(Georgios Petasis) Actually, under windows there is a limited selection of colours, as the progress bars can have a state (normal, error, paused, partial).

The trick is to use PP_FILL (5) and PP_FILLVERT (6), instead of PP_CHUNK (3) and PP_CHUNKVERT (4) that are used currently by ttk.

I don't know if they are supported by XP (I don't have an XP machine to check), but for Vista & 7 works.

In fact, since the vista theme is implemented in tcl, it can be easily tweaked (file vistaTheme.tcl):

ttk::style element create Horizontal.Progressbar.pbar vsapi \
    PROGRESS 5 {user3 2 user2 3 user1 4 {} 1} -padding 8
ttk::style element create Vertical.Progressbar.pbar vsapi \
    PROGRESS 6 {user3 2 user2 3 user1 4 {} 1} -padding 8

(I just added 5 & 6 part ids instead of 4 & 4 (was this 4 on horizontal an error instead of 3?), and I assigned the error state to user3, the paused to user2, and partial to user1.

With these changes, the following code:

package require Tk
for {set i 1} {$i < 6} {incr i} {
   pack [ttk::progressbar .$i -length 400] -fill x -expand 1 -padx 4 -pady 10
   .$i configure -value [expr $i*20]

}

.1 state user1
.2 state user2
.3 state user3

gives the following visual effect under windows 7:

http://www.ellogon.org/~petasis/tcl/Images/TtkProgressModes.png

(error is red, paused is yellow, partial is blue, and the normal one is green).

Perhaps we want to add similar support to ttk?

I forgot to mention that I found this info here: [1 ]

(It has all the states for all parts).

  Animated bar

HaO 2014-01-18: On a thread on clt titled 'Windows glowing "pulseoverlay" ttk::progressbar?' Georgios Petasis provided a patch to have a Windows animated progress bar:

If you replace this file: http://www.ellogon.org/~petasis/tcl/ttk/ttkWinXPTheme.c in tk/win sources, and recompile Tk, you will get animated progressbars by adding the following:

ttk::style element create Horizontal.Progressbar.animation vsapi \
     PROGRESS 8 {user3 2 user2 3 user1 4 {} 1} \
     -padding 0 -margins -8 -pbaranimated 1
ttk::style layout Horizontal.TProgressbar {
      Horizontal.Progressbar.trough -sticky nswe -children {
        Horizontal.Progressbar.pbar -side left -sticky ns -children {
          Horizontal.Progressbar.animation -sticky nswe
        }
      }
}

The updated theme file is needed for this "-pbaranimated 1", which does the custom drawing of the overlay. Works only for horizontal progressbars, that are in determine mode:

http://www.ellogon.org/~petasis/tcl/ttk/2014-01-17_01-45-12.png

Mark Garvey asked why his backport to 8.5 does not work

Thanks George, looks brilliant! Do you know of any reason why this couldnt work in 8.5. I've adapted the code and recompiled in 8.5.13 but can't seem to get it to work.

Is this the correct code:

ttk::style element create Horizontal.Progressbar.animation vsapi \
     PROGRESS 8 {user3 2 user2 3 user1 4 {} 1} \
     -padding 0 -margins -8 -pbaranimated 1
ttk::style layout Horizontal.TProgressbar {
      Horizontal.Progressbar.trough -sticky nswe -children {
        Horizontal.Progressbar.pbar -side left -sticky ns -children {
          Horizontal.Progressbar.animation -sticky nswe
        }
      }
}


toplevel .top
ttk::progressbar .top.pb -value 49 -mode determinate -style Horizontal.TProgressbar
pack .top.pb 

Answer

What happened to the line:

ttk::style configure TProgressbar -period 20 -maxphase 240

Without this: NO animation :D This informs the style that the progress bar is animated. -period is the update interval (in ms), and maxphase the total steps of the animation. These are standard Ttk, I simply re-used them.

  Thin progress bar

Alexandru 2015-07-17 How to make the ttk::progressbar thinner or in general change the thickness of the progress bar (see also https://groups.google.com/forum/#!topic/comp.lang.tcl/REUNmqccMgA )

I had some difficulties trying to change the thickness of the progress bar under Windows. After many tries and help got on comp.lang.tcl, it seems that the most robust solution is to use a frame of fixed height and place instead of pack:

set progress 50
pack [ttk::frame .a -height 10] -expand 1 -fill x
place [ttk::progressbar .progress -orient horizontal -mode determinate -maximum 100 -variable progress] -in .a -relheight 1.0 -relwidth 1.0