1

我尝试运行此代码,但它不断抛出上述错误。问题肯定出在我试图在屏幕/按钮上显示进度条的 Progress() 函数中。我尝试了几件事,但没有任何效果。请帮忙!我正在使用 pytube3,python 3.7

from pytube import YouTube
from tkinter import * 
import threading

full_file_size = 0

def progress(stream=None, chunk=None, file_handle=None, remaining=None):
    file_downloaded = full_file_size - remaining
    per = (file_downloaded/full_file_size)*100
    # btn_text.set(f"{per} % Downloading")
    print(f"{per}%") 

def download_stream():
    global full_file_size
    input_url = entry_var.get()
    ob = YouTube(input_url, on_progress_callback=progress)
    strm = ob.streams.first()
    full_file_size = strm.filesize
    # print(type(file_size))
    print(full_file_size/(1024*1024), "MB")
    
    save_path = "C:\\Users\\hp\\Desktop\\visual programs\\youtube_download"
    print("Your video is downloading")
    
    strm.download(save_path)
    print("Dowload Complete")
    entry_widget.delete(0,END)
    btn_text.set("Download")
    
def continue_thrad():
    thread = threading.Thread(target=download_stream)
    thread.start()
    print('Thread is working')

window = Tk()
window.geometry("500x600")
window.title("Youtube Downloader.")

img = PhotoImage(file='logo.png')
l1 = Label(window, image=img)
l1.pack()

entry_var = StringVar()
btn_text = StringVar()
btn_text.set("Download")

entry_widget = Entry(window, textvar=entry_var, font=("Verdana, 20"), relief=SUNKEN)
entry_widget.pack(fill=X, padx=20, pady= 10)

b1=Button(window, textvariable=btn_text, font=("Verdana, 20"), command=continue_thrad)
b1.pack()

window.mainloop()
4

1 回答 1

0
def progress(chunk, file_handle, remaining):

上面的参数传入进度函数来解决问题。[注意:不要传入None参数]

于 2020-12-28T06:30:04.630 回答