问题
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