ich schreibe gerade einen Downloader für private Zwecke und will mir dabei den Status des Downloads anzeigen lassen.
Per print in die Shell klappt das ganze auch. Jetzt will ich den Status in ein Label schreiben lassen, das wird jedoch erst nach dem Download verändert.
Jemand ne Idee wiso?
Code: Alles auswählen
import urllib.request, re, os, io
from tkinter import *
def mergeLists(a, b):
for i in b:
a.append(i)
return a
def listJoin(l, glue):
s = ''
for i in range(len(l)):
s += l[i]
if i < len(l):
s += glue
return s
def dllHook(cnt, blockSize, totalSize):
#print(b / c * 100)
global txtStatus
txtStatus.set(cnt)
# txtStatus.set('%f (%i / %i)' % (((cnt*blockSize)/totalSize*100), cnt*blockSize, totalSize))
print('%f (%i / %i)' % (((cnt*blockSize)/totalSize*100), cnt*blockSize, totalSize))
def main():
global url, tenshiUrl, localPath, txtStatus
txtStatus.set('Lade Daten...')
files = []
files = getFiles(url) # Liefert eine Liste von URLs
for f in files:
localDir = listJoin(f.split('/')[:-1], '/').replace(tenshiUrl, localPath)
localFile = localDir + f.split('/')[-1]
print(localDir)
if not os.path.isdir(localDir):
os.makedirs(localDir)
print('Create %s' % localDir)
# Datei schon heruntergeladen?
if os.path.isfile(localFile):
print('%s already exists.' % localFile)
else:
print('Download %s ...' % localFile)
print(f, localFile)
urllib.request.urlretrieve(f, localFile, dllHook)
break
url = 'http://../'
tenshiUrl = 'http://../'
localPath = './'
# Status GUI
gui = Tk()
txtStatus = StringVar()
labStatus = Label(gui, textvariable=txtStatus)
labStatus.pack(fill = X, side = LEFT)
txtStatus.set('Willkommen!')
btnStart = Button(gui, text='Start', command=main)
btnStart.pack(side = LEFT)
gui.mainloop()