Search code examples
pythontkintertkinter-button

Is it possible to remove the "animation" when a tkinter button is clicked?


I have a button defined in tkinter that has the same background color as the screen, so it's just text on the screen. The problem that I'm having is that when the button is clicked, the background changes to white while it is being clicked, which contrasts horribly with the dark background. I am trying to disable this. I tried setting activebackground='SystemButtonFace', but this didn't work for some reason. I'm not really sure what's happening. Here is the code that defines the button. tk.Button(main_canvas, activebackground='SystemButtonFace', bg='#404040')


Solution

  • When setting the activebackground property, you need to specify the corresponding color. The following code does not have this problem.

    import tkinter as tk
    
    root = tk.Tk()
    
    button_bg_color = '#404040'
    button_fg_color = '#FFFFFF'
    
    root.config(bg=button_bg_color)
    
    button = tk.Button(
        root,
        text="Click Me",
        bg=button_bg_color,
        fg=button_fg_color,
        activebackground=button_bg_color,
        activeforeground=button_fg_color,
        bd=0
    )
    
    button.pack(pady=20)
    
    root.mainloop()