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
相关产品推荐
相关产品推荐

