Bind Escape to Exit

Binny V A binnyva at hotmail.com
Sun Mar 13 05:12:07 EST 2005


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.

This is the code that I used

---------------------------------
from Tkinter import *

class Application(Frame):
	def createWidgets(self):
		self.lab = Label(text="Hello World")
		self.lab.pack()
		
	def __init__(self, master=None):
		Frame.__init__(self, master)
		self.pack()
		self.createWidgets()
		self.bind('<Key-Escape>',self.quit)

app = Application()
app.mainloop()

---------------------------------

It is displaying everything properly, but it is not quiting
when the escape key is pressed.

What am I doing wrong

Thank You,
Binny V A
http://www.geocities.com/binnyva/code



More information about the Python-list mailing list