How to change the button color when the button is press?

蹲街弑〆低调 提交于 2021-01-29 07:03:00

问题


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?

My code is:

b = Button(frame1, text='Quit', command=quit_func)
b.grid(row=6,column=4,pady=5,padx=10)            
b.config( background="darkorange1", foreground="white")

回答1:


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.



来源:https://stackoverflow.com/questions/56334628/how-to-change-the-button-color-when-the-button-is-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!