I am trying to display downloaded images in tkinter Progressbar
, It is working but the progressbar finishes way before the all images are downloaded. I asked a very similar question tkinter updating progress bar on thread progress, My idea is to update progressbar depending on how many files were created using len(os.listdir('.'))
to count.
import tkinter
from tkinter.ttk import Progressbar
import os,uuid,requests,threading
import numpy as np
def bar():
temp = 0
for lst in chunks:
threads.append(threading.Thread(target=download_image, args=(lst)))
for x in threads:
x.start()
while temp<len(links):
progress['value'] = temp
root.update_idletasks()
temp =len(os.listdir('.'))
print("closing threads")
for i in threads:
i.join()
temp =len(os.listdir('.'))
progress['value'] = temp
print('done')
root.destroy()
with open('image_urls.txt','r') as f:
links = f.read().split('\n') #links to image urls
threads =[]
chunks = [i.tolist() for i in np.array_split(links, 10) if i.size>0]
root = tkinter.Tk()
root.geometry("400x300")
root.title('Downloader v1')
progress = Progressbar(root, orient = tkinter.HORIZONTAL,
length = 250, mode = 'determinate',maximum=len(links))
progress.pack(pady = 100)
notice = tkinter.Label(root, text=str(len(links)),
fg="grey2",)
notice.place(x=350, y=100)
compose_button = tkinter.Button(root, text = 'Start', command = bar)
compose_button.pack()
root.mainloop()