So i've found this HTTP downloader in python, and I wanted to modify it. I've been trying to add a ttk progressbar, to no avail, but I have no idea why it isn't working!
Here is my code:
import urllib2
import Tkinter
import ttk
url = 'http://kharg.czystybeton.pl/pendulum%20-%20%5B2005%5D%20hold%20your%20colour/05.%20through%20the%20loop.mp3'
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
global file_size_dl
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
f.close()
root = Tk()
root.title('Downloading... ' + file_name)
progressbar = ttk.Progressbar(orient=HORIZONTAL, length=500, mode='determinate', variable=file_size_dl, maximum=file_size)
progressbar.pack(side="top")
progressbar.start()
root.mainloop()
Any ideas? Thanks!