如何改变ttk.progressBar颜色在python [英] How to change ttk.progressBar color in python

查看:2541
本文介绍了如何改变ttk.progressBar颜色在python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我可以改变我的ttk.progressBar的颜色吗?现在显示绿色,我很想有它的蓝色。

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)


推荐答案

你可以改变进度条的颜色,但它是棘手的。首先,你需要理解,如果你使用默认的主题,这是默认的主题,如果你没有在tk.style指定一个主题。然后它会将它需要的所有信息传递给操作系统,这将使用它的样式来绘制图形,忽略你传递的样式信息。意味着它将在Windows上绘制一个Window的样式绿色progressbar等等。你需要做的是将主题更改为ttk绘制的自定义主题。尝试clam风格,它是ttk允许你选择的最好看的样式之一。这里是一个工作适应摘录从我写的脚本:

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 working

这篇关于如何改变ttk.progressBar颜色在python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆