V
V
Vasiliy_Ivanov2021-12-10 10:59:50
Python
Vasiliy_Ivanov, 2021-12-10 10:59:50

ProgressBar only shows progress at the end, what should I do?

Good day, I am making a program that downloads videos from YouTube, but when using the progress bar, it does not update at the time of downloading the video, but only shows the full download at the end. I use pytube and tkinter libraries.
Here is the whole code:

import pytube
from threading import Thread
import tkinter as tk
from tkinter import ttk

win = tk.Tk()
win.geometry('250x50')

file_size = 0


def progress(stream=None, chunk=None, remaining=0):
    file_downloaded = (file_size - remaining)
    per = (file_downloaded / file_size) * 100
    pb.config(value=format(per))


def download():
    global file_size
    video_url = 'ссылка на видео'
    save_path = 'C:\\Users\\parfe\\Desktop'

    video = pytube.YouTube(video_url, on_progress_callback=progress).streams.filter(res='720p', file_extension='mp4', progressive=True).desc().first()
    file_size = video.filesize
    video.download(save_path)


def start():
    thread = Thread(target=download)
    thread.start()


pb = ttk.Progressbar(win, length=200)
pb.pack()

tk.Button(win, text='Start', command=start).pack()

win.mainloop()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question