current position: home » tkinter » text

Tkinter custom color progress bar

    Some friends need to customize the progress bar of the color, but it is impossible to make it by default. It must be set through the style style. Because the progress bar is a component under the TTK module, the color of the progress bar should be changed by setting the theme.


Here are the codes:

from tkinter import *
from tkinter.ttk import *

root=Tk()
root.title('aying7.com')

style = Style()
style.theme_use('clam') 
# Self test for each subject,'winnative','clam','alt','default','classic' Test successful. 
# windows theme:('winnative','clam','alt','default','classic','vista','xpnative')

style.configure("1.Horizontal.TProgressbar", troughcolor ='blue', background='green') 
style.configure("2.Horizontal.TProgressbar", troughcolor ='red', background='yellow')
style.configure("3.Horizontal.TProgressbar", troughcolor ='black', background='red')
style.configure("4.Horizontal.TProgressbar", troughcolor ='white', background='lightblue')

P1 = Progressbar(root,style="1.Horizontal.TProgressbar",length=180)
P1.pack(padx=10,pady=5)
P1.start()

P2 = Progressbar(root,style="2.Horizontal.TProgressbar",length=180)
P2.pack(padx=10,pady=5)
P2.start()

P3 = Progressbar(root,style="3.Horizontal.TProgressbar",length=180)
P3.pack(padx=10,pady=5)
P3.start()

P4 = Progressbar(root,style="4.Horizontal.TProgressbar",length=180)
P4.pack(padx=10,pady=5)
P4.start()

root.mainloop()

Operation diagram

1.PNG

source: Typing.news

Link to this article: http://typing.news/post/1.html

<< To the top Next >>

search

Classification

sponsor link

Good Luck To You!