因此,我正在玩下面的代码,但由于我不知道的原因,有些东西是错误的,当执行时,什么也没有发生。在
'''
Created on Jul 12, 2014
@author: nick
'''
import urllib2
import urllib
from Tkinter import *
#import tkinter.messagebox
#import turtle
from PIL import *
import PIL.Image
import os
import webbrowser
def FetchURI():
response = urllib2.urlopen(custom.get())
labelText.set('OK')
html = response.read()
with open("/home/nick/Desktop/Imagenet/URIs.txt", 'w') as outfile:
outfile.write(html)
return
def aboutMe():
url = ('https://blablabla/wikis/home')
webbrowser.open_new(url)
return
def openURIS():
PATH = "/home/nick/Desktop/Imagenet/URIs.txt"
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
print "File is there and readable"
else:
print "Either missing or nor readable"
f = open(PATH)
aboutURIS.delete(1.0, END)
URIstring = ""
for i in f:
URIstring += i
aboutURIS.insert(END, URIstring)
f.close()
return
#Download images
def download_img():
f = open("/home/nick/Desktop/Imagenet/URIs.txt")
lines = f.readlines()
f.close()
#print(lines)
for i in xrange(len(lines)):
#t = urllib2.urlopen(urllib2.Request(lines[i]))
image = urllib.URLopener()
image.retrieve(lines[i], "/home/nick/Desktop/Imagenet/img%s" % i)
#urllib.urlretrieve(lines[i], "/home/nick/Desktop/Imagenet/test%s" % i)
return
def openBB():
pass
def openFeatures():
pass
def openMap():
pass
app = Tk()
app.title('Simple Tkinter GUI')
app.geometry('400x500')
menubar = Menu(app)
filemenu = Menu(menubar,tearoff=0)
filemenu.add_command(label="Open URIs", command=openURIS)
filemenu.add_command(label="Bounding Boxes", command=openBB)
filemenu.add_command(label="Features", command=openFeatures)
filemenu.add_command(label="Mapping", command=openMap)
filemenu.add_separator()
filemenu.add_command(label="Quit", command=app.quit)
menubar.add_cascade(label="File", menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About us", command=aboutMe)
menubar.add_cascade(label="Help", menu=helpmenu)
app.config(menu=menubar)
aboutURIS = Text(app)
aboutURIS.insert(END, "Paste link into the little box to fetch URIs")
aboutURIS.pack()
labelText = StringVar()
labelText.set('Click button below')
label1 = Label(app, textvariable=labelText, height=4)
label1.pack()
#checkBoxVal = IntVar()
#checkBox1 = Checkbutton(app, variable=checkBoxVal, text="Hello?")
#checkBox1.pack()
custom = StringVar(None)
legend = Entry(app, textvariable=custom)
legend.pack()
button1 = Button(app, text='Click to fetch URIs', width=20, command=FetchURI)
button1.pack(side='top', padx=15 , pady=15)
app.mainloop()
这个函数属于一个Tkinter GUI,我不觉得它有什么关系。我也很难理解这个相当愚蠢的错误。URIs.txt
文件存在于Imagenet
目录中,因此这里肯定有其他错误。可能是for
循环或f.readlines
?在
有什么反馈吗?在
^{pr2}$
文件或文件权限的问题
请检查
/home/nick/Desktop/Imagenet/URIs.txt
文件是否存在?如果存在,那么它是否具有读取权限?在相关问题 更多 >
编程相关推荐