【问题标题】:Why python progress bar starts after completing the download为什么完成下载后python进度条开始
【发布时间】:2021-04-28 07:01:48
【问题描述】:

我在我的 python 程序中添加了一个进度条, 但它在下载完成后启动。

我下载了一个大文件,它在很长一段时间后才开始。 当进度条从 0% 开始时,文件已下载。

我能做些什么呢? 我需要在下载开始时显示它。

完整代码:https://github.com/GH0STH4CKER/Youtube_to_mp3/blob/main/Youtube_to_mp3.py

进度条码:

def download(url, fname):
    resp = requests.get(url, stream=True)
    total = float(content_length)
    with open(fname, 'wb') as file, tqdm(
            desc=fname,
            total=total,
            unit='iB',
            unit_scale=True,
            unit_divisor=1024,
    ) as bar:
        for data in resp.iter_content(chunk_size=1024):
            size = file.write(data)
            bar.update(size)

download(d_link,songname)    

【问题讨论】:

    标签: python python-3.x download progress-bar


    【解决方案1】:

    也许尝试在不同的线程中运行它,因为我认为它会在之后执行

    【讨论】:

    【解决方案2】:
        def progres_(self, streams, chunk, bytes_remaining):
            percentage = (float(abs(bytes_remaining - self.size_inBytes) / self.size_inBytes)) * float(100)
            self.progres_bar["value"] = percentage
            self.progres_bar.update()
            self.lbl_percentage.config(text=f" Downloading: {str(round(percentage, 2))}%")
            if round(percentage, 2) == 100:
                self.lbl_message.config(text="Download Completed", fg="green")
                self.btn_download.config(state=tk.DISABLED)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 2013-06-15
      • 2015-11-08
      • 1970-01-01
      • 2018-01-08
      相关资源
      最近更新 更多