Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I change the background color of the non-completed part of ttk::progressBar

I am using base Tk widgets which take the default colors of X11 (old-style).

However, I want to also use ttk::progressBar. I am trying to have the widget have a certain background color.

I know I can control the color of the "completed" part of the bar using ttk::style and -background:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

set p .progressBar
ttk::style configure TProgressbar -background yellow -font fixed
ttk::progressbar $p -orient horizontal -variable progressBarValue -length 100  
pack $p -padx 5 -pady 5 -fill x
set progressBarValue 20

The progress bar is displayed as follows:

enter image description here

However, I would like to know if it is possible to change the background color of the widget (from light grey to a different color). I am using just this widget from ttk.

Also I would like to know if it possible to display a text ("20%") or the widget provides only a progress bar without an overlapped text

>Solution :

That is the ‘trough’. Try setting the style configuration ‘-troughcolor’. This is shared with the scrollbar so ‘Horizontal.Progressbar.trough’ is the specific full name of the element and ‘Vertical.Progressbar.trough’ for the vertical orientation.

You can’t add a text element and get it updated by the widget. You could change the style layout to add such an element but it would have to get configured by the style as the widget has no code to update a text element. So you’ll have to put a label widget in the right place.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading