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
>
> 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
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
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 |
+------------------------------------------------------------------------+
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
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
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
Dear all,
Many Thanks to all of you for your valuable help!!!
Cesare