python - 选择 tkinter 时按钮会瞬间改变颜色
问题描述
是否有一个最佳实践可以让 tkinter 按钮在被选中时瞬间改变颜色(以便用户获得按钮被按下的视觉反馈)。
我读过time.sleep()
在 tkinter GUI 中使用它不是一个好主意。
当我的按钮被按下时,代码发生得如此之快,以至于即使我有一个button.config()
改变颜色的命令,它也不会在不使用的情况下发生time.sleep()
有什么建议么?
解决方案
我想这可能是你想要的:
Button(background=normal_color, foreground=text_color,
activebackground=pressed_color, activeforeground=pressed_text_color)
这会将按钮从按下按钮更改normal_color
为pressed_color
。
这实际上是一个简单的问题,答案很简单,但我也不得不到处寻找。最后通过阅读http://effbot.org/tkinterbook/button.htm找到了这个答案。
推荐阅读
- python - 除缩写外的正则表达式清理
- javascript - 为 React Router 使用单例是否安全?
- javascript - 执行 eslint 时找不到模块“json-schema”错误
- node.js - NodeJs .env 文件中的 Linux 环境变量
- ajax - 如何使用laravel响应成功下载ajax文件
- python - 在 python 中快速重新投影空间数据
- c# - Entity Framework Core 通过数据本身改变 fk
- javascript - 音乐播放器仅从一个文件夹播放
- javascript - 带有弹出框的动画
- javascript - 反应应用程序:所有三个按钮都被自己点击,我如何阻止这种情况发生(反应非常新)