Reputation: 6063
I am trying to write a file downloader that has a GUI and displays the progress of the file being downloaded. I would like it to either display a text percentage, a progress bar or both. I am sure this can be done in Python, but I'm just not sure how.
I am using Python 2.6 on MS Windows XP.
Upvotes: 2
Views: 1690
Reputation: 28656
The easiest progress bar dialog would probably be with EasyDialogs for Windows (follows the same api as the EasyDialogs module that is included with the mac version of python)
For determining the progress of the download, use urllib.urlretrieve() with a "reporthook".
Something like this:
import sys
from EasyDialogs import ProgressBar
from urllib import urlretrieve
def download(url, filename):
bar = ProgressBar(title='Downloading...', label=url)
def report(block_count, block_size, total_size):
if block_count == 0:
bar.set(0, total_size)
bar.inc(block_size)
urlretrieve(url, filename, reporthook=report)
if __name__ == '__main__':
url = sys.argv[1]
filename = sys.argv[2]
download(url, filename)
There are of course other libraries available for richer GUI interfaces (but they are larger or more difficult if this is all you need). The same goes for the downloads: there are probably faster things than urllib, but this one is easy and included in the stdlib.
Upvotes: 3