Change color when button is sunken Tkinter
<p>How could I make it, so when any button in my program is sunken (so being clicked) that button gets a certain background color (white) for 1 sec.</p>

<p>I was thinking of something like this:</p>

<p>Whenever ButtonClicked = Sunken, ButtonClicked['bg'] = 'white' for 1 sec</p>

<p>But I have lots of buttons, and every button has a different function. So what is an easy to implement program so this happens to all buttons?</p>

<p>The simplest solution is to create your own custom button class, and add the behavior to that class.</p>

<p>You can use <code>after</code> to arrange for the color to be restored after some amount of time.</p>

<p>For example:</p>

<pre><code>class CustomButton(tk.Button):
    def __init__(self, *args, **kwargs):
        self.altcolor = kwargs.pop("altcolor", "pink")
        tk.Button.__init__(self, *args, **kwargs)
        self.bind("&lt;ButtonPress&gt;", self.twinkle)

    def twinkle(self, event):
        # get the current activebackground...
        bg = self.cget("activebackground")

        # change it ...
        self.configure(activebackground=self.altcolor)

        # and then restore it after a second
        self.after(1000, lambda: self.configure(activebackground=bg))
</code></pre>

<p>You would use it like you would any other <code>Button</code>. It takes one new argument, <code>altcolor</code>, which is the extra color you want to use:</p>

<pre><code>b1 = CustomButton(root, text="Click me!", altcolor="pink")
b2 = CustomButton(root, text="No, Click me!", altcolor="blue")
</code></pre>

python button tkinter click