python - Listbox updating -
when run displays percent after it's done downloading there way make display downloads it?
listbox = listbox(admin) listbox.grid(row=19, column=9) def download0(runums, song): chunks = 10000 dat = '' runum = runums.replace(' ', '%20') url = runum down = urlopen(url) downso = 0 tota = down.info().getheader('content-length').strip() tota = int(tota) while 1: = down.read(chunks) downso += len(a) if not a: break dat += percent = float(downso) / tota percent = round(percent*100, 1) sys.stdout.write(str(percent)) sys.stdout.flush() sys.stdout.write("\b"*4) listbox.insert(end, percent)
the tkinter event loop (started mainloop()
) runs on single thread. spins, reacting events (e.g. mouse clicks), repainting widgets, , on. when button clicked start download, control passed download0()
function. until control returns event loop, no widgets redraw unless tell them to.
so while download in progress need tell widget redraw itself:
listbox.insert(end, percent) listbox.update_idletasks()
Comments
Post a Comment