【发布时间】:2015-04-12 14:06:01
【问题描述】:
我拼凑了一个小程序来下载专利。我想将转义键绑定到关闭窗口的函数,但我真的不知道如何实现这一点。我已将转义键绑定到“退出”功能,但有人可以帮我弄清楚如何编写关闭文本输入窗口的功能吗?
我是菜鸟。
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 > 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('<Return>', patdload)
master.bind('<Escape>',quit)
#b = Button(master, text = "GET", width = 10, command = patdload)
#b.pack()
mainloop()
编辑:这是新的错误:
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 <lambda>
master.bind('<Escape>', 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
【问题讨论】:
标签: python python-2.7 tkinter