首页 > 解决方案 > 选择 tkinter 时按钮会瞬间改变颜色

问题描述

是否有一个最佳实践可以让 tkinter 按钮在被选中时瞬间改变颜色(以便用户获得按钮被按下的视觉反馈)。

我读过time.sleep()在 tkinter GUI 中使用它不是一个好主意。

当我的按钮被按下时,代码发生得如此之快,以至于即使我有一个button.config()改变颜色的命令,它也不会在不使用的情况下发生time.sleep()

有什么建议么?

标签: pythonpython-3.xtkinter

解决方案


我想这可能是你想要的:

Button(background=normal_color, foreground=text_color,
       activebackground=pressed_color, activeforeground=pressed_text_color)

这会将按钮从按下按钮更改normal_colorpressed_color

这实际上是一个简单的问题,答案很简单,但我也不得不到处寻找。最后通过阅读http://effbot.org/tkinterbook/button.htm找到了这个答案。


推荐阅读