Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:53:17+00:00 2026-06-16T00:53:17+00:00

I need a progress to show during file download for Python 3. I have

  • 0

I need a progress to show during file download for Python 3.
I have seen a few topics on Stackoverflow, but considering that I’m a noob at programming and nobody posted a complete example, just fractions of it, or the one that I can make work on Python 3, none are good for me…

additional info:

ok, so i have this:

from urllib.request import urlopen
import configparser
#checks for files which need to be downloaded
print('    Downloading...')
file = urlopen(file_url)
#progress bar here
output = open('downloaded_file.py','wb')
output.write(file.read())
output.close()
os.system('downloaded_file.py')

script is run through python command line

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:53:18+00:00Added an answer on June 16, 2026 at 12:53 am

    There is urlretrieve() that downloads an url to a file and allows to specify a reporthook callback to report progess:

    #!/usr/bin/env python3
    import sys
    from urllib.request import urlretrieve
    
    def reporthook(blocknum, blocksize, totalsize):
        readsofar = blocknum * blocksize
        if totalsize > 0:
            percent = readsofar * 1e2 / totalsize
            s = "\r%5.1f%% %*d / %d" % (
                percent, len(str(totalsize)), readsofar, totalsize)
            sys.stderr.write(s)
            if readsofar >= totalsize: # near the end
                sys.stderr.write("\n")
        else: # total size is unknown
            sys.stderr.write("read %d\n" % (readsofar,))
    
    urlretrieve(url, 'downloaded_file.py', reporthook)
    

    Here’s a GUI progress bar:

    import sys
    from threading import Event, Thread
    from tkinter import Tk, ttk
    from urllib.request import urlretrieve
    
    def download(url, filename):
        root = progressbar = quit_id = None
        ready = Event()
        def reporthook(blocknum, blocksize, totalsize):
            nonlocal quit_id
            if blocknum == 0: # started downloading
                def guiloop():
                    nonlocal root, progressbar
                    root = Tk()
                    root.withdraw() # hide
                    progressbar = ttk.Progressbar(root, length=400)
                    progressbar.grid()
                    # show progress bar if the download takes more than .5 seconds
                    root.after(500, root.deiconify)
                    ready.set() # gui is ready
                    root.mainloop()
                Thread(target=guiloop).start()
            ready.wait(1) # wait until gui is ready
            percent = blocknum * blocksize * 1e2 / totalsize # assume totalsize > 0
            if quit_id is None:
                root.title('%%%.0f %s' % (percent, filename,))
                progressbar['value'] = percent # report progress
                if percent >= 100:  # finishing download
                    quit_id = root.after(0, root.destroy) # close GUI
    
        return urlretrieve(url, filename, reporthook)
    
    download(url, 'downloaded_file.py')
    

    On Python 3.3 urlretrieve() has different reporthook interface (see issue 16409). To workaround it, you could access the previous interface via FancyURLopener:

    from urllib.request import FancyURLopener
    urlretrieve = FancyURLopener().retrieve
    

    To update the progress bar within the same thread, you could inline urlretrieve() code:

    from tkinter import Tk, ttk
    from urllib.request import urlopen
    
    def download2(url, filename):
        response = urlopen(url)
        totalsize = int(response.headers['Content-Length']) # assume correct header
        outputfile = open(filename, 'wb')
    
        def download_chunk(readsofar=0, chunksize=1 << 13):
            # report progress
            percent = readsofar * 1e2 / totalsize # assume totalsize > 0
            root.title('%%%.0f %s' % (percent, filename,))
            progressbar['value'] = percent
    
            # download chunk
            data = response.read(chunksize)
            if not data: # finished downloading
                outputfile.close()
                root.destroy() # close GUI
            else:
                outputfile.write(data) # save to filename
                # schedule to download the next chunk
                root.after(0, download_chunk, readsofar + len(data), chunksize)
    
        # setup GUI to show progress
        root = Tk()
        root.withdraw() # hide
        progressbar = ttk.Progressbar(root, length=400)
        progressbar.grid()
        # show progress bar if the download takes more than .5 seconds
        root.after(500, root.deiconify)
        root.after(0, download_chunk)
        root.mainloop()
    
    download2(url, 'downloaded_file.py')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an NSMenuItem that I need to update to show a progress (like
I need to make a file download that displays a loading icon during the
I need to show a progress bar to the user who requests a file
I'm writing an iphone application and need to show a progress bar that shows
I need to show Progress circle attached over to the TextView but it should
I need to show the secondary progress of a ProgressDialog on Android, but it
I am developing an app in Cocoa. I need to show a progress at
I have to create a progress bar in a webapp. I need a thread
I have an interesting problem. I need to do a progress bar from an
I have a program to process very large files. Now I need to show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.