How to change ttk::progressbar color?

2081 views
Skip to first unread message

cbava...@csc.com

unread,
May 20, 2011, 10:48:13 AM5/20/11
to
Hi,

Under ActiveTcl 8.5.9.0, I tried to change ttk::progressbar color,
unsuccessfully.

Is there a way to change the color from the default green to another?

Many Thanks,
Cesare

Manfred Stelzhammer

unread,
May 20, 2011, 4:40:39 PM5/20/11
to

ttk::style configure TProgressbar -background red


Regards
Manfred

cb58

unread,
May 23, 2011, 8:33:21 AM5/23/11
to
On 20 Mag, 22:40, Manfred Stelzhammer <manf...@antispam.at> wrote:

> Am 2011-05-20 16:48, schrieb cbavazz...@csc.com:
>
> > Hi,
>
> > Under ActiveTcl 8.5.9.0, I tried to change ttk::progressbar color,
> > unsuccessfully.
>
> > Is there a way to change the color from the default green to another?
>
> > Many Thanks,
> > Cesare
>
>   ttk::style configure TProgressbar -background red
>
> Regards
> Manfred

Thanks Manfred,
I tried to do so, but it is still not working ... as if the -
background option not referred to the color bar itself.
For sure I did something wrong; anyway, Please see code below, thanks
again:

package require Tk
package require Ttk

wm withdraw .

set w .ttkprogress
catch {destroy $w}
toplevel $w
wm title $w "Progress Bar Demonstration"
wm iconname $w "ttkprogress"
wm geometry $w +300+300

set font "Courier 10"

ttk::frame $w.f
pack $w.f -fill both -expand 1
set w $w.f

proc doBars {op args} {
foreach w $args {
$w $op
}
}

ttk::progressbar $w.p2 -mode indeterminate -length 200

#--------------------------------
# Now, trying to change color ...
#--------------------------------


ttk::style configure TProgressbar -background red

ttk::button $w.start -text "Start Progress" -command [list doBars
start $w.p2]
ttk::button $w.stop -text "Stop Progress" -command [list doBars stop
$w.p2]

grid $w.p2 - -pady 5 -padx 10
grid $w.start $w.stop -padx 10 -pady 5
grid configure $w.start -sticky e
grid configure $w.stop -sticky w
grid columnconfigure $w all -weight 1

Kevin Walzer

unread,
May 23, 2011, 10:03:32 AM5/23/11
to
On 5/23/11 8:33 AM, cb58 wrote:

>
> Thanks Manfred,
> I tried to do so, but it is still not working ... as if the -
> background option not referred to the color bar itself.
>

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.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

cb58

unread,
May 23, 2011, 10:26:43 AM5/23/11
to

>
> 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.
>
> --Kevin
>
> --
> Kevin Walzer
> Code by Kevinhttp://www.codebykevin.com

Hi Kevin,

I have the same feeling about ...

However, this habit is a bit confusing to me as, in case of error, the
Vista native bar gets red!
That's the reason why I wished to be able to change ttk::progressbar
color accordingly, and realized it is always stuck on green.

It seems to be a bug ... (?)

Cesare

Gerald W. Lester

unread,
May 23, 2011, 11:50:06 AM5/23/11
to

My guess is that the Vista native bar has a state. Have you tried changing
the state of the progressbar?

Is so, and nothing happens it may be that this was not mapped in the windows
implementation (may be a new feature/property that Tk is not mapping for
reason of compatibility with older versions of windows).

--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Georgios Petasis

unread,
May 23, 2011, 2:53:28 PM5/23/11
to Kevin Walzer
Στις 23/5/2011 17:03, ο/η Kevin Walzer έγραψε:
> On 5/23/11 8:33 AM, cb58 wrote:
>
>>
>> Thanks Manfred,
>> I tried to do so, but it is still not working ... as if the -
>> background option not referred to the color bar itself.
>>
>
> 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.
>
> --Kevin
>

Dear Kevin,

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?

Regards,

George

Georgios Petasis

unread,
May 23, 2011, 2:57:24 PM5/23/11
to Gerald W. Lester
Στις 23/5/2011 18:50, ο/η Gerald W. Lester έγραψε:
> On 5/23/11 9:26 AM, cb58 wrote:
>>
>>>
>>> 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.
>>>
>>> --Kevin
>>>
>>> --
>>> Kevin Walzer
>>> Code by Kevinhttp://www.codebykevin.com
>>
>> Hi Kevin,
>>
>> I have the same feeling about ...
>>
>> However, this habit is a bit confusing to me as, in case of error, the
>> Vista native bar gets red!
>> That's the reason why I wished to be able to change ttk::progressbar
>> color accordingly, and realized it is always stuck on green.
>>
>> It seems to be a bug ... (?)
>
> My guess is that the Vista native bar has a state. Have you tried
> changing the state of the progressbar?
>
> Is so, and nothing happens it may be that this was not mapped in the
> windows implementation (may be a new feature/property that Tk is not
> mapping for reason of compatibility with older versions of windows).
>

Dear Gerald,

Yes, this is correct, progress bars under windows do have a state. But
currently ttk offers no support for this by default, but it is quite
easy to fix this. The fix for the vista theme actually is very easy (as
it is in Tcl). The vsapi element really rocks!

Best regards,

George

Georgios Petasis

unread,
May 23, 2011, 2:58:54 PM5/23/11
to Kevin Walzer


I forgot to mention that I found this info here:
http://207.46.16.248/en-us/library/bb773210%28VS.85%29.aspx

(It has all the states for all parts).

George

Harald Oehlmann

unread,
May 24, 2011, 1:44:53 AM5/24/11
to
FYI, I have put the essence of this brilliant posting to the wiki:
http://wiki.tcl.tk/ttk::progressbar
Feel free to modify it
-Harald

cb58

unread,
May 24, 2011, 4:00:37 AM5/24/11
to

Dear all,

Many Thanks to all of you for your valuable help!!!

Cesare

bisi...@gmail.com

unread,
Sep 21, 2018, 6:13:56 PM9/21/18
to
Hi all,

I am still trying to implement this solution but don't understand how to ask for another state of the progress bar. Please what should I do with following example code:

N.B.: I already changed vistaTheme.tcl

BPStyle = ttk.Style()
BPStyle.theme_use('vista')
BPStyle.configure("Style0.Horizontal.TProgressbar", troughcolor ='white', background='white')
BPStyle.configure("Style1.Horizontal.TProgressbar", troughcolor ='green', background='white')
BPStyle.configure("Style2.Horizontal.TProgressbar", troughcolor ='red', background='white')
BPStyle.configure("Style3.Horizontal.TProgressbar", troughcolor ='white', background='green')
BPStyle.configure("Style4.Horizontal.TProgressbar", troughcolor ='white', background='yellow')
BPStyle.configure("Style5.Horizontal.TProgressbar", troughcolor ='white', background='red')
#
BarreProgressionConnexionAcquisition = ttk.Progressbar(fenetre,style="Style0.Horizontal.TProgressbar",orient="horizontal",maximum=12,length=12,mode="determinate")
BarreProgressionConnexionAcquisition.place(x=0,y=0)
BarreProgressionShiftLight1 = ttk.Progressbar(fenetre,style="Style3.Horizontal.TProgressbar",orient="horizontal",maximum=478,length=478,mode="determinate")
BarreProgressionShiftLight1.place(x=12,y=0)
BarreProgressionShiftLight2 = ttk.Progressbar(fenetre,style="Style4.Horizontal.TProgressbar",orient="horizontal",maximum=350,length=350,mode="determinate")
BarreProgressionShiftLight2.place(x=490,y=0)
BarreProgressionShiftLight3 = ttk.Progressbar(fenetre,style="Style5.Horizontal.TProgressbar",orient="horizontal",maximum=175,length=175,mode="determinate")
BarreProgressionShiftLight3.place(x=840,y=0)
#
BarreProgressionShiftLight1.start()
BarreProgressionShiftLight2.start()
BarreProgressionShiftLight3.start()

Brad Lanam

unread,
Sep 21, 2018, 6:29:56 PM9/21/18
to
I am assuming you made the proper changes to vistaTheme.tcl.

I don't know python, but something like:
(should be red). The state is associated with the progress bar, not the style.

BarreProgressionShiftLight3 = ttk.Progressbar(fenetre,style="Style5.Horizontal.TProgressbar",orient="horizontal",maximum=175,length=175,mode="determinate",state="user3")

bisi...@gmail.com

unread,
Sep 22, 2018, 4:56:19 AM9/22/18
to
With your purposal, we get:

Traceback (most recent call last):
File "C:\dynoTOOLS\05_dynoPy_v4_0\dynoLog_v4_0.pyw", line 848, in <module>
BarreProgressionShiftLight1 =
ttk.Progressbar(fenetre,style="Style1.Horizontal.TProgressbar",orient="horizontal",maximum=450,length=450,mode="determinate",state="user3")
File
"C:\Users\mP\AppData\Local\Programs\Python\Python36-32\lib\tkinter\ttk.py",
line 1014, in __init__
Widget.__init__(self, master, "ttk::progressbar", kw)
File
"C:\Users\mP\AppData\Local\Programs\Python\Python36-32\lib\tkinter\ttk.py",
line 559, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File
"C:\Users\mP\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py",
line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-state"




I also tried somethings like BarreProgressionShiftLight1.state("user2"),
but in this case I get:

Traceback (most recent call last):
File "C:\dynoTOOLS\05_dynoPy_v4_0\dynoLog_v4_0.pyw", line 849, in <module>
BarreProgressionShiftLight1.state("user2")
File
"C:\Users\mP\AppData\Local\Programs\Python\Python36-32\lib\tkinter\ttk.py",
line 595, in state
return self.tk.splitlist(str(self.tk.call(self._w, "state", statespec)))
_tkinter.TclError: Invalid state name u



Thank you a lot for your help with this tricky problem !!

Brad Lanam

unread,
Sep 22, 2018, 11:03:01 AM9/22/18
to
On Saturday, September 22, 2018 at 1:56:19 AM UTC-7, bisi...@gmail.com wrote:
> I also tried somethings like BarreProgressionShiftLight1.state("user2"),
> but in this case I get:
>
> Traceback (most recent call last):
> File "C:\dynoTOOLS\05_dynoPy_v4_0\dynoLog_v4_0.pyw", line 849, in <module>
> BarreProgressionShiftLight1.state("user2")
> File
> "C:\Users\mP\AppData\Local\Programs\Python\Python36-32\lib\tkinter\ttk.py",
> line 595, in state
> return self.tk.splitlist(str(self.tk.call(self._w, "state", statespec)))
> _tkinter.TclError: Invalid state name u
>
>
>
> Thank you a lot for your help with this tricky problem !!

This looks like the right thing to do, but why is the state name
only getting passed a 'u' instead of 'user2'. Oh, I see.
Again I don't know python, make a list of states and pass that in.

BarreProgressionShiftLight1.state( list("user2") )

bisi...@gmail.com

unread,
Sep 22, 2018, 12:52:37 PM9/22/18
to
Hi Brad,

Thank you again for your help, here I had lots of hope but it still just look at the "u":
Traceback (most recent call last):
File "C:\dynoTOOLS\05_dynoPy_v5_0\dynoLog_v5_0.pyw", line 930, in <module>
BarreProgressionConnexionAcquisition.state(list('user2'))

Brad Lanam

unread,
Sep 22, 2018, 1:05:43 PM9/22/18
to
Well, my ignorance of Python can't help with this any more.
It appears that python is doing a 'splitlist' on 'user2' and is splitting
it character by character. But I don't know how to create a list in python.

You need help from Bryan Oakley or someone else who knows Python.
Or ask for help in the python newsgroups.

bisi...@gmail.com

unread,
Sep 22, 2018, 1:44:11 PM9/22/18
to
I will try to contact him, thank's a lot ! =)
Message has been deleted

harij...@gmail.com

unread,
Dec 18, 2018, 1:21:48 AM12/18/18
to
hello everyone,
i am a budding software designer and wish to join google. my problem is when i checked your posts, i was not able to understand that why you use this type of code

> grid $w.p2 - -pady 5 -padx 10
> grid $w.start $w.stop -padx 10 -pady 5
> grid configure $w.start -sticky e
> grid configure $w.stop -sticky w
> grid columnconfigure $w all -weight 1

is it idustrial neccesty or something like that? why don't you write like that
> ttk.Button.grid(pady=5, padx=10)
ins't it a good way. Any help would be appreciated. Thanks in advance.
by,
Harijot
from: india
age: 14 years

Harald Oehlmann

unread,
Dec 18, 2018, 4:42:41 AM12/18/18
to
Am 18.12.2018 um 07:21 schrieb harij...@gmail.com:
> hello everyone,
> i am a budding software designer and wish to join google. my problem is when i checked your posts, i was not able to understand that why you use this type of code
>
>> grid $w.p2 - -pady 5 -padx 10
>> grid $w.start $w.stop -padx 10 -pady 5
>> grid configure $w.start -sticky e
>> grid configure $w.stop -sticky w
>> grid columnconfigure $w all -weight 1
>
> is it idustrial neccesty or something like that? why don't you write like that
>> ttk.Button.grid(pady=5, padx=10)
> ins't it a good way. Any help would be appreciated. Thanks in advance.
> by,
> Harijot
> from: india
> age: 14 years
>

The cited code is tcl. I suppose, you use another language (python,
perl, ruby) with tk where the syntax is different.
Reply all
Reply to author
Forward
0 new messages