Sunday, 30 May 2021

How can I have Python TTK use the Windows OS default progress bar theme?

How in TTK can I use the OS default loader theme instead of the tkinter one?

Loading - Known

Loading - Unknown

This is an example of a normal progress bar.

from tkinter import *
from tkinter.ttk import *

root = Tk()
root.geometry('400x250+1000+300')

progress_bar = Progressbar(root, orient=HORIZONTAL, length=100, mode='indeterminate')
progress_bar.pack(expand=True)
progress_bar.start()

root.mainloop()

I get a progress bar, but it isn't themed like the OS default progress bar is.

TTK-themed progress bar

I thought that perhaps a style could make it look like that, so I listed the styles:

Style().theme_names() # ('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative')

I tried each one like so:

from tkinter import *
from tkinter.ttk import *

root = Tk()
root.geometry('400x250+1000+300')

os_default_style = Style()
os_default_style.theme_use('THEME')
os_default_style.configure('osdefault.Horizontal.TProgressbar')
progress_bar = Progressbar(root, orient=HORIZONTAL, length=100, mode='indeterminate', style='osdefault.Horizontal.TProgressbar')
progress_bar.pack(expand=True)
progress_bar.start()

root.mainloop()

They produce ones that are similar, but none are the system. How do I make it look exactly like one used by the system?



from How can I have Python TTK use the Windows OS default progress bar theme?

No comments:

Post a Comment