【问题标题】:How to change the button color when the button is press?按下按钮时如何更改按钮颜色?
【发布时间】:2019-10-13 12:50:11
【问题描述】:

我有一个橙色背景的按钮。但是在按下按钮时,颜色不会保持不变。它更改为默认颜色。释放按钮后,我恢复了相同的颜色。按下按钮时是否可以更改按钮的颜色?

我的代码是:

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

【问题讨论】:

    标签: python button tkinter


    【解决方案1】:

    Button 小部件将activebackgroundactiveforeground 作为参数。

    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()
    

    有关按钮小部件选项的完整列表,您可以阅读here

    【讨论】:

      猜你喜欢
      • 2020-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      相关资源
      最近更新 更多