TIP #442: Display text in progressbars

Title:Display text in progressbars
Version:$Revision: 1.11 $
Authors: René Zaumseil <rzaumseil at kkg dot ch>
Kevin B Kenny <kevin dot b dot kenny at gmail dot com>
Andreas Leitgeb <avl at logic dot at>
Kevin Kenny <Kevin dot B dot Kenny at gmail dot com>
Created:Wednesday, 17 February 2016


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:


The string to display.


The font used to render the text.


The color of the text.


The anchoring of the text.


The justification of the string.


The length at which the string will be automatically wrapped.

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


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.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows