Bind Escape to Exit

Martin Franklin mart.franklin at gmail.com
Sun Mar 13 15:33:18 EST 2005


Kent Johnson wrote:
> Binny V A wrote:
> 
>> Hello Everyone,
>>
>> I am new to python and I am trying to get a program to close a 
>> application when the Escape Key is pressed.
> 
> 
> Here is a version that works. The changes from yours:
> - Bind <Escape>, not <Key-Escape>

These amount to the same thing AFAIK

> - Bind the key to the root, not the frame

This is the 'fix'  Tkinter's Tk (and Toplevel) widgets will allow key 
bindings, Frames do not.

> - Define a quit() method that takes an event parameter

Yep the bind'ing will pass an event object to the callback.

just FYI, you may be interested in the Tkinter mailing list:-

http://mail.python.org/mailman/listinfo/tkinter-discuss

also available from gmane:-

gmane.comp.python.tkinter


Martin.






More information about the Python-list mailing list