tkinter 标签的背景颜色不会改变(python 3.4)

编程入门 行业动态 更新时间:2024-10-18 10:13:46
本文介绍了tkinter 标签的背景颜色不会改变(python 3.4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在用 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/viewtopic.php?f=12&t=16212

This solution was posted by dietrich41 here : http://www.python-forum/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 07:19:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   背景   标签   tkinter   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!