嗨 我做了一個音樂下載程序,它的效果很好,它會告訴你它完成的百分比,然後如果我移動窗口,它會停止下載。 我做了一個不同的小腳本,可以在網上下載指定的mp3,我可以根據需要隨意移動它,並且它不會停下來。當你移動Tkinter窗口停止程序
我沒有提出代碼的唯一原因是它非常長。它大約有1500條線路。這是我下載一個文件的小腳本。
是否有人知道它爲什麼會阻止程序運行? 小腳本:
from Tkinter import *
from urllib2 import *
admin = Tk()
Admin = Tk()
listbox = Listbox(admin, bg="PURPLE")
listbox.pack()
def __init__(self, master):
def replay():
Admin.destroy()
os.system('WhaleWire.exe')
frame = Frame(master)
frame.pack()
image1 = PhotoImage(file="whalewire.gif")
w = image1.width()
h = image1.height()
master.geometry("%dx%d+0+0" % (w, h))
# tk.Frame has no image argument
panel1 = Label(master, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
panel1.image = image1
self.e = Entry(frame)
self.e.grid(row=0, column=0)
b = Button(frame, text='Search', command=self.whale)
b.grid(row=0, column=1)
def library():
path = 'C:\WhaleWire\Downloaded'
aw=[]
for infile in glob.glob(os.path.join(path,'*.mp3')):
libr = infile.split('Downloaded',1)
aw.append('\n')
aw.append(infile)
la = Label(Admin,width=100,height=50, text=aw).grid(row=0,column=7)
b2s = Button(Admin,text='Search', command=replay).grid(row=0,column=8)
b11 = Button(frame, text='Library', command=library)
b11.grid(row=0, column=3)
def fores():
chunks = 10000
dat = ''
song = '3 rounds and a sound'
url = 'http://bonton.sweetdarkness.net/music/Blind%20Pilot%20--%203%20Rounds%20and%20A%20Sound.mp3'
down = urlopen(url)
downso = 0
tota = down.info().getheader('Content-Length').strip()
tota = int(tota)
while 1:
a = down.read(chunks)
downso += len(a)
if not a:
break
dat += a
percent = float(downso)/tota
percent = round(percent*100, 1)
listbox.insert(END, percent)
listbox.update()
listbox.delete(0, END)
listbox.insert(END, percent)
listbox.update()
button = Button(Admin, text='Download', command=fores)
button.pack()
button = Button(Admin, text='Download', command=fores)
button.pack()
mainloop()
所以......你向我們展示了一個可行的程序,並且我們應該猜測你沒有向我們展示的程序是如何失敗的? – 2011-05-06 11:01:23