Skip to main content
 首页 » 编程设计

python之无法使用样式设置背景颜色 ttk python os x

2025年05月04日18jiqing9006

对于此代码片段,我希望标签的背景颜色为红色。 def createWidgets(self):

    style = ttk.Style() 
    style.configure("Red.TLabel", foreground="green", background="red") 
 
    self.label1 = ttk.Label(textvariable=self.numberArray[0][0],style="Red.TLabel") 
    self.label1.pack() 

我获得了绿色前景色,但无法更改背景色。 这是在 OS X 上。我正在使用 ActiveState 的 tcl 和 python。同样的问题出现在 Python 3.2 和 2.7

请您参考如下方法:

You'll sometimes try to change an option that is supposed to exist according to element options, but it will have no effect. As an example, you can't modify the background color of a button in the "aqua" theme used by Mac OS X. While there are valid reasons for these cases, at the moment its not easy to discover them, which can make experimenting frustrating at times.

摘自本教程 http://www.tkdocs.com/tutorial/styles.html