按下按钮时如何更改按钮颜色? [英] How to change the button color when the button is press?
本文介绍了按下按钮时如何更改按钮颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个橙色背景的按钮.但是在按下按钮时,颜色不会保持不变.它更改为默认颜色.释放按钮后,我会恢复原色.按下按钮时是否可以更改按钮的颜色?
I have a button that has an orange background. But on pressing the button the colour does not remain the same. It changes to its default colour. And on release of button I get back the same colour. Is it possible to change the colour of the button while the button is being pressed?
我的代码是:
b = Button(frame1, text='Quit', command=quit_func)
b.grid(row=6,column=4,pady=5,padx=10)
b.config( background="darkorange1", foreground="white")
推荐答案
Button
小部件将 activebackground
和 activeforeground
作为参数.
Button
widget takes activebackground
and activeforeground
as parameters.
from tkinter import *
root = Tk()
b = Button(root, text='Quit', command="")
b.grid(row=6,column=4,pady=5,padx=10)
b.config(background="darkorange1", foreground="white",
activebackground="darkorange1", activeforeground="white")
root.mainloop()
有关按钮小部件选项的完整列表,您可以阅读这里.
For a full list of button widget options, you can read it up here.
这篇关于按下按钮时如何更改按钮颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文