TIP 442: Display text in progressbars

Author:         RenĂ© Zaumseil <[email protected]>
Author:         Kevin B Kenny <[email protected]>
Author:         Andreas Leitgeb <[email protected]>
Author:         Kevin Kenny <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        17-Feb-2016
Keywords:       Tk
Tcl-Version:    8.7
Tk-Branch:      tip-442


Horizontal progress bars should support the ability to display text inside the progress bar. Buttons should allow justification of multiline texts.


It is often useful to be able to display text directly on top of a progress bar. This text might be a description of the progress percentage, what is currently being done, or even just a label giving the overall task that is progressing.

The ttk::progressbar command can easily enhanced to provide this support, and there is no interference with existing code as this functionality can be done by just introducing new options. The options required are from the list of usual Tk well-known option names.

Also the ttk::button command can easily be enhanced to provide justification of multiline text.


Text will be displayed only on horizontal ttk::progressbar. To control the text appearance the following new options will be added:

-text: The string to display.

-font: The font used to render the text.

-foreground: The color of the text.

-anchor: The anchoring of the text.

-justify: The justification of the string.

-wraplength: The length at which the string will be automatically wrapped.

To justify multiline text in ttk::button a new option will be added:

-justify: The justification of the string.

Notes for future improvements

The underlying Tk text rendering engine supports rotated text, which would make support on vertical progress bars possible. But control of the rotation angle might be required (according to whether the text is rotated left or right, or stays unrotated).

The most contrasting color of the text will depend where on the progress bar it is placed. This is not an effect that is simply reproduced with the Tk script level, but is easy to apply during rendering.


A patch implementing these changes and updating the documentation is available in the fossil repository in the tip-442 branch.

Implementation is heavily borrowed from the ttk::label widget featuring these same options. The names, meanings, and default values of the options are the same as for ttk::label. The rendering and processing is the same as for this latter widget.

Example of use

    package require Tk
    proc moveit {} {
      for {set i 0} {$i < 100} {incr i} {
        .p step ; update ; after 100
    pack [ttk::progressbar .p -value 0 -maximum 50 -orient horizontal -length 500]
    .p configure -anchor c -foreground blue -justify right \
            -text "-anchor c -foreground blue -justify right -wraplength 100" \
            -wraplength 100
    .p configure -anchor e -font {Arial 10 bold} -foreground green -justify center \
            -text "-anchor e -font {Arial 10 bold} -foreground green -justify center -wraplength 250" \
            -wraplength 250
    .p configure -text "-anchor w -foreground red -justify left -wraplength 50" \
            -anchor w -foreground red -justify left -wraplength 50
    .p configure -orient vertical -text "Cannot be seen"


This document has been placed in the public domain.