# coding: utf-8 import Tkinter as Tk import ScrolledText import re,urllib,thread # Ctrl+Vで貼り付けた複数のURLをダウンロード (2011/12/26) # download.pyw としてutf-8で保存してダブルクリックで起動 #--- class App(Tk.Frame): def __init__(self,window): Tk.Frame.__init__(self,window) self.pack() self.start() def start(self): self.URL = ScrolledText.ScrolledText(self,width=80,height=12) self.URL.pack() f1 = Tk.Frame(self) f1.pack() self.GET = Tk.Button(f1,text='Get',command=lambda: thread.start_new_thread( self.http,() )) self.GET.pack(side='left') self.END = Tk.Button(f1,text='End',command=self.quit) self.END.pack(side='left') def http(self): t = self.URL.get('1.0',Tk.END) l = re.findall(r'(https?\:\/\/\S+)',t) self.GET.configure(state=Tk.DISABLED) self.END.configure(state=Tk.DISABLED) for u in l: f = re.sub(r'(?:%[a-zA-Z0-9]+|[^\w\-\.])+','_',u) if 196 < len(f): f = f[0:196] g = urllib.urlopen(u) p = open(f,'wb',0) while 1: b = g.read(8192) if not b: break p.write(b) p.close() g.close() self.URL.delete('1.0',Tk.END) self.GET.configure(state=Tk.NORMAL) self.END.configure(state=Tk.NORMAL) #--- def main(): window = Tk.Tk() window.title('app_download') app = App(window) app.mainloop() window.destroy() #--- if __name__ == '__main__': main()