更改 tkinter 中按钮的颜色适用于 Windows,但不适用于 Mac OSX [英] Changing color of buttons in tkinter works on Windows but not Mac OSX

查看:43
本文介绍了更改 tkinter 中按钮的颜色适用于 Windows,但不适用于 Mac OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上试过了,它可以工作,我猜是 OSX 错误?

以下代码由于某种原因不起作用,按钮保持白色

The following code does not work for some reason and the button stays white

z = Button(frame, text="Nothing Scheduled", bg = "blue" command=lambda ..., width=15)
z.grid(row=x, column=1)

但是,由于某种原因,设置标签的背景可以正常工作

However, setting the background of a label works correctly for some reason like below

Label(frame, text=times[x], bg="blue").grid(row=x, column=0)

所以我最终得到了以下 GUI,如下所示

So I end up with the following GUI, shown below

我知道 this 帖子,但是我没有使用 ttk,所以我认为这不适用于这里.我只是在 Python 3.6.4 中使用 from tkinter import *,但是我在 Mac OSX 上

I am aware of the bug detailed in this post, however I am not using ttk so I don't think that applies here. I am simply using from tkinter import * in Python 3.6.4, however I am on Mac OSX

我也尝试过 z.config(bg="blue") 以及 z["bg"]="blue",但都失败了

I have also tried z.config(bg="blue") as well as z["bg"]="blue", and both of those fail as well.

推荐答案

在这个页面tcl/tk wiki 列出了一些与 Mac 相关的问题以及标签和按钮背景的颜色.例如:

In this page of the tcl/tk wiki are listed some problems related to Mac and the color of labels and buttons's backgrounds. For example:

...

Mac OS X 背景色不应为白色,而应为#ececec.由于 winfo rgb 在 mac 颜色上无法正常工作,因此很难获得正确的默认颜色.

The Mac OS X background color should not be white, it should be #ececec. Since winfo rgb does not work properly on the mac colors, this makes it difficult to get the proper default color.

...等

致敬!

这篇关于更改 tkinter 中按钮的颜色适用于 Windows,但不适用于 Mac OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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