Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change ttk.progressBar color in python

Does anyone know how I can change the color of my ttk.progressBar? It now shows a green color, and I would love to have it blue.

import ttk
self.progressBar = ttk.Progressbar(frame3, length=560, maximum=100, mode='determinate');
self.progressBar.place(x=-5, y=60)
like image 856
Coryza Avatar asked Nov 22 '12 10:11

Coryza


1 Answers

You can change the color of a progressbar, but it is tricky. First, you need to understand that if you use the default theme, which is the default theme if you do not specify a theme in the tk.style. Then it will pass all the information it needs to the operating system, which will do the drawing using its style, disregarding style info you passed it. meaning it will draw a Window's style green progressbar on Windows and so on and so forth. What you need to do is change the theme to a custom one that ttk draws. Try the "clam" style, it is one of the best looking styles that ttk allows you to chose from. here is a working adapted excerpt from a script I wrote:

import Tkinter as tk
import ttk as ttk
root = tk.Tk()
frame = tk.Frame(root)
frame.grid()
s = ttk.Style()
s.theme_use('clam')
s.configure("red.Horizontal.TProgressbar", foreground='red', background='red')
ttk.Progressbar(frame, style="red.Horizontal.TProgressbar", orient="horizontal",
                length=600, mode="determinate", maximum=4, value=1).grid(row=1, column=1)
frame.pack()

and here is a picture confirming it works.

Progress bar color

like image 139
clan Avatar answered Oct 02 '22 20:10

clan