title: How do I bind the escape key to close this window
body: <p>I have a little program that I've cobbled together to download patents.  I'd like to bind the escape key to a function to close the window, but I don't really know how to make this happen.  I've bound the escape key to a "quit" function, but can someone help me figure out how to write the function to close the text input window?  </p>
  
  <p>I'm a noob.</p>
  
  <pre><code>from Tkinter import *
  import urllib
  
  master = Tk()
  e = Entry(master)
  e.pack()
  
  e.focus_set()
  
  
  def patdload(self, event=None): 
      allnums = e.get()
      index = 0
      test = allnums.find('.')
      if test &gt; 0:
          sep = 0
          while sep != -1:
              sep = allnums.find('.', index) 
              if sep != -1:
                  patno = allnums[index:sep]
              elif sep == -1:
                  patno = allnums[index:]
  
              #patno = e.get()
              paturl = "http://patentimages.storage.googleapis.com/pdfs/US" + patno + ".pdf"
              urllib.urlretrieve (paturl, (patno + ".pdf"))
              index = sep + 1
  
  
      else:
          patno = e.get()
          paturl = "http://patentimages.storage.googleapis.com/pdfs/US" + patno + ".pdf"
          urllib.urlretrieve (paturl, (patno + ".pdf"))
  
  
  def quit #help#:
  
  master.bind('&lt;Return&gt;', patdload)
  
  master.bind('&lt;Escape&gt;',quit)
  
  
  
  #b = Button(master, text = "GET", width = 10, command = patdload)
  #b.pack()
  
  
  mainloop()
  </code></pre>
  
  <p>Edit: here's the new error:</p>
  
  <pre><code>Exception in Tkinter callback
  Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1532, in __call__
  return self.func(*args)
  File "C:\Python27\PatentGet.py", line 42, in &lt;lambda&gt;
  master.bind('&lt;Escape&gt;', lambda x: close())
  File "C:\Python27\PatentGet.py", line 39, in close
  master.widthdraw() # if you want to bring it back
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1894, in __getattr__
  return getattr(self.tk, attr)
  AttributeError: widthdraw
  </code></pre>