如何重置python tkinter按钮的背景颜色? [英] How to reset background color of a python tkinter button?
本文介绍了如何重置python tkinter按钮的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的问题,解析了无数搜索结果,还没有找到简单的答案.如果找不到某些东西,我将一个非常紧急的按钮设置为红色,以便用户先单击它.单击后,我想像 button.config(bg='')
一样将背景设置回正常.我试过灰色",但颜色不对.
Simple question, have parsed numerous search results, haven't found a simple answer. I set a very urgent button to red if something is not found so users click it first. Once clicked, I want to set the background back to normal like button.config(bg='')
. I tried 'grey' but it's not the right color.
我将它设置为什么?
推荐答案
您可以在更改按钮之前询问它的颜色.保存颜色,稍后再恢复:
You can ask the button what color it is before you change it. Save the color, and then restore it later:
orig_color = the_button.cget("background")
the_button.configure(background="red")
...
the_button.configure(background=orig_color)
这篇关于如何重置python tkinter按钮的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文