I've seen the following code for binding the Escape Key to a Tkinter GUI:

import Tkinter as tk

def exit():
    root.destroy()

root = tk.Tk()
root.bind("<Escape>", exit)
root.mainloop()

However, when I add this to my GUI program, I don't get a response when Esc key is pressed. It does nothing. Any suggestions?

Give your function an argument, in this case just an empty one.

def exit(event):

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.