当前位置:首页 » tkinter » 正文

tkinter自定义颜色的进度条Progressbar

有朋友需要自定义颜色的进度条Progressbar,但在默认情况下,是不可能做出来的,必须要通过Style样式来设置,因为进度条是ttk模块下的组件,所以要通过设置主题来改变进度条的颜色。


以下是代码:               冫亓垚

from tkinter import *
from tkinter.ttk import *

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

style = Style()
style.theme_use('clam') 
# 各主题自行测试,'winnative','clam','alt','default','classic'测试成功. 
# windes主题:('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() # 来自 aying7.com

运行图

1.PNG

 

经过 aying7.com 测试,有些主题支持进度度颜色自定义,有些不支持


来源:阿英工作室

本文链接:http://www.aying7.com/post/1.html

tkinter  
    << 到顶啦 下一篇 >>

    赞助商链接

    湘公网安备 43011102000200号 - 湘ICP备08100508号