Display text in progressbarsRené ZaumseilKevin B KennyAndreas LeitgebKevin Kenny$Revision: 1.11 $Tk
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.
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.
ICAgIHBhY2thZ2UgcmVxdWlyZSBUaw==ICAgIHByb2MgbW92ZWl0IHt9IHs=ICAgICAgZm9yIHtzZXQgaSAwfSB7JGkgPCAxMDB9IHtpbmNyIGl9IHs=ICAgICAgICAucCBzdGVwIDsgdXBkYXRlIDsgYWZ0ZXIgMTAwICAgICAgfQ==ICAgIH0=ICAgIHBhY2sgW3R0azo6cHJvZ3Jlc3NiYXIgLnAgLXZhbHVlIDAgLW1heGltdW0gNTAgLW9yaWVudCBob3Jpem9udGFsIC1sZW5ndGggNTAwXQ==ICAgIC5wIGNvbmZpZ3VyZSAtYW5jaG9yIGMgLWZvcmVncm91bmQgYmx1ZSAtanVzdGlmeSByaWdodCBcICAgICAgICAgICAgLXRleHQgIi1hbmNob3IgYyAtZm9yZWdyb3VuZCB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