Skip to content
Advertisement

python: tkinter/urllib/requests – GUI not responding when running download command

I tried making a GUI where there is a download button and it downloads a file from the internet. There is also a progressbar which shows progress of the download..

the whole code:

JavaScript

but when i click on the download button, the whole window stops responding.. and after some time, when the download is finished, it responds.. and the progressbar becomes 100% done..

Advertisement

Answer

Try this:

JavaScript

First of all, your code had a few mistakes:

  • You keep opening the file in "wb" mode, which overrides the last chunk that you downloaded.
  • You divide the size by 1024 for no reason.
  • Also the file you are downloading is very small. There is no need to iterate over it’s contents. The code above assumes that you have a large file

Things I did:

  • I added a tkinter loop that uses global variables to communicate with a new thread.
  • That thread downloads the file.
  • I also changed the url to a large file (> 1GB) just to check that it’s working properly.
  • I also changed it so it opens the file only once so we can save the full file
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement