Search code examples
pythonpython-3.xtkinterwindows-10

Python TKinter progressbar style issue


I'm writing a TKinter GUI app and having issue with the progressbar style configuration. I'm running the same code in different machines and one time it is ok and in the other it is not.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
app = tk.Frame(root)
app.pack()    
app.green_style = ttk.Style()
app.green_style.configure("myStyle.Horizontal.TProgressbar",  background='yellow',foreground = 'blue')
app.progress = ttk.Progressbar(root, length=200, mode='determinate',style="myStyle.Horizontal.TProgressbar")
app.progress.pack()
app.progress['value'] = 75
app.mainloop()

In Linux with python 3.7.3 it creates a yellow progressbar:

linux 3.7.3 progressbar

But in Windows 10 with Python 3.10.11 the style doesn't change:

windows 3.10.11 progressbar

Can you please help me understand why the Windows progress bar style is not updating?

Thanks!


Solution

  • From the official document:

    Some options are only available for specific themes.

    So try another theme, like "winnative":

    import tkinter as tk
    from tkinter import ttk
    
    root = tk.Tk()
    app = tk.Frame(root)
    app.pack()
    app.green_style = ttk.Style()
    app.green_style.theme_use("winnative")  # use another theme
    app.green_style.configure("myStyle.Horizontal.TProgressbar",
                              background="yellow", foreground="blue")
    app.progress = ttk.Progressbar(root, length=200, mode="determinate",
                                   style="myStyle.Horizontal.TProgressbar")
    app.progress.pack(expand=1, padx=10, pady=10)
    app.progress["value"] = 75
    app.mainloop()
    

    Result:

    enter image description here