tkinter 标签的背景颜色不会改变(python 3.4) [英] Background color of tkinter label will not change (python 3.4)

查看:36
本文介绍了tkinter 标签的背景颜色不会改变(python 3.4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Python 3.4 中的 Tkinter 制作一个小部件.出于某种原因,我无法从默认的灰色更改标签的背景颜色.标签的代码是这样的:

I am making a widget with Tkinter in python 3.4. For some reason, I cannot change a label's background color from the default grey. The code for the label is something like this:

self.label = ttk.Label(master, text="Label Text", 
                       foreground="blue", background="yellow")

其他一切正常.我可以更改前景(文本)颜色,但背景不会改变,无论我使用的是 label.config()、label['background'] 还是其他任何东西.

Everything else works fine. I can change the foreground (text) color, however the background will not change, whether I am using label.config(), label['background'], or whatever.

如果我为 Python 2.7 编写它,我可以更改背景,但我在 3.4 中使用 Tkinter 的教程,所以这是不可取的.

I can change the background if I write it for Python 2.7, but I am using tutorials for Tkinter in 3.4, so this is undesirable.

推荐答案

此错误是由 Mac OSX 上的 'aqua' ttk 样式引起的.当设置为不确定"模式时,它也会破坏ttk.Progressbar".要解决这两个问题,请在root = Tk()"之后插入以下代码以更改样式...

This bug is caused by the 'aqua' ttk style on Mac OSX. It also breaks 'ttk.Progressbar' when set to 'indeterminate' mode. To fix both issues insert the following code after 'root = Tk()' to change the style ...

style = ttk.Style()
style.theme_use('classic') # Any style other than aqua.

此解决方案由dietrich41 发布此处:http://www.python-forum.org/viewtopic.php?f=12&t=16212

This solution was posted by dietrich41 here : http://www.python-forum.org/viewtopic.php?f=12&t=16212

我在运行 Python 3.4.1 的 Mac 上对其进行了测试.

I tested it on a Mac running Python 3.4.1.

这篇关于tkinter 标签的背景颜色不会改变(python 3.4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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