You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac Ventura下Python3.11.5中Tkinter按钮点击后背景色无法修改的问题

Tkinter按钮背景色无法修改的问题解决

问题现象

尝试点击按钮时更新其背景色,但只有前景色(fg)生效,背景色(bg)无任何变化,测试代码如下:

from tkinter import *
def demoColorChange():
    button1.configure(bg='red', fg='blue')
parent = Tk()
parent.geometry('500x500')
button1 = Button(parent, text = 'click me!', command= demoColorChange )
button1.pack()
parent.mainloop()

运行环境:Mac Ventura 系统,Python 3.11.5 版本

解决方法

安装tkmacosx库,并将按钮的导入语句替换为:

from tkmacosx import Button

替换后按钮背景色可正常更新。


内容的提问来源于stack exchange,提问作者El_Loco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 13:34:50