How to disable text shaking when I click a button?
Question: I am working with buttons in Tkinter, python.

The thing is when I click in one button the text of the button shakes. It
might be a default behavior for this widget and I don't know how to disable it
and make it static.

Does anyone know how to fix this?


Answer: I assume that you mean the relief change from raised to sunken when you click
a button.

This is what I found on <http://wiki.tcl.tk/1048> (click 'Show Discussion' to
see it):

> Unfortunately, the relief used when you click is hardcoded (as 'sunken'), so
> you can't configure it per-widget without hacking the Tk internals for the
> binding for buttons.

So the simplest way around this would be to always make the button appear
sunken

    
    
    MyButton = Tkinter.Button(
        self.frame, 
        text = "Foobar", 
        command = self.foobar, 
        relief=Tkinter.SUNKEN
    )
    

The disadvantage of that is that it might make the button look unresponsive.

You can also use a widget other than a button to be used as a clickable item
(suggested by Joel Cornett). Here is a simple example with a label used as a
button:

    
    
    import Tkinter
    
    class main:
            def __init__(self,root):
                    # make a label with some space around the text
                    self.lbl1 = Tkinter.Label(root,
                                              width = 16, height = 4,
                                              text = "Foobar")                
                    self.lbl1.pack()
    
                    # Call a function when lbl1 is clicked
                    # <Button-1> means a left mouse button click
                    self.lbl1.bind("<Button-1>", self.yadda)
                    self.lbl1.bind("<Enter>", self.green)
                    self.lbl1.bind("<Leave>", self.red)
    
            def yadda(self, event):
                    self.lbl1.config(text="Clicked!")
    
            def green(self, event):
                    self.lbl1.config(bg="green")
    
            def red(self,event):
                    self.lbl1.config(bg="red")
    
    if __name__ == "__main__":
        root = Tkinter.Tk()
        main(root)
        root.mainloop() 
    

