[Tkinter-discuss] Button look

Michael Lange klappnase at freenet.de
Thu Jun 10 15:56:09 EDT 2004


On Wed, 9 Jun 2004 15:39:44 -0300 
"Batista, Facundo" <FBatista at uniFON.com.ar> wrote:

> Have a simple GUI.
> 
> One text entry, two buttons. When you press each button, something is done
> with the text you entered and it takes about 10 seconds.
> 
> I want the first button to be triggered with the Enter key. So I binded the
> <Return> key to the same function that the button.
> 
> It works but I also want that the button look "pressed" when I press the key
> and the function starts, and look "unpressed" when the function finishes.
> 
> How can I tell the button to look "pressed" and "unpressed"?
> 
> I'm on Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
> on win32.
> 
> Thank you!

I don't have a win32 box here, on my linux box the following works fine:

class Mybutton(Tkinter.Button):
    def __init__(self, master, **kw):
        Tkinter.Button.__init__(self, master, **kw)
        self.bind('<Return>', lambda event: self.event_generate('<space>'))

and then use the Mybutton class like a regular Tkinter.Button.

Michael



More information about the Tkinter-discuss mailing list