Bind Escape to Exit
Harlin Seritt
harlinseritt at yahoo.com
Sun Mar 13 05:41:27 EST 2005
Binny,
The only way I could think to get this done was like so:
from Tkinter import *
class Application: # take away the inherited class
def end(self, event):
self.master.destroy()
def createWidgets(self):
self.lab = Label(text="Hello World")
self.lab.pack()
def __init__(self, master):
self.master = master # Create a class version of master:
self.master
self.frame = Frame(self.master) # Change master to self.master
self.frame.pack()
self.createWidgets()
self.master.bind('<Escape>', self.end) # Change <Key-Escape> to
<Escape>, link bind to self.end
root = Tk() # Use a tk instance
a = Application(root)
root.mainloop() # Call tk.mainloop()
I am almost certain that I had the same dilemma as you. Good luck. If
you find a better way please post it.
Thanks,
Harlin Seritt
More information about the Python-list
mailing list