我有pytube和tkinter的python应用程序

我有pytube和tkinter的python应用程序,python,tkinter,pytube,python-3.9,Python,Tkinter,Pytube,Python 3.9,我做了一个应用程序,你可以下载youtube视频并选择下载位置。问题是,它只是有时起作用 这就是它在控制台中给出的错误:Tkinter回调回溯异常(最近一次调用):文件“C:\Users\User\AppData\Local\Programs\Python\Python39\lib\Tkinter\\ uu init\uuuuuuuuuuuu.py”,第1885行,在调用返回self.func(*args)文件“C:\Python\VideoDownloader\VideoDownloader\

我做了一个应用程序,你可以下载youtube视频并选择下载位置。问题是,它只是有时起作用

这就是它在控制台中给出的错误:
Tkinter回调回溯异常(最近一次调用):文件“C:\Users\User\AppData\Local\Programs\Python\Python39\lib\Tkinter\\ uu init\uuuuuuuuuuuu.py”,第1885行,在调用返回self.func(*args)文件“C:\Python\VideoDownloader\VideoDownloader\VideoDownloader.py”,第39行,在downloadVideo ytbvideo=YouTube中(ytbLink).streams.filter(progressive=True,文件扩展名为mp4').order_by('resolution').desc().first()文件“C:\Users\User\AppData\Local\Programs\Python39\lib\site packages\pytube\\uuu main\uuuuuuuuuuuuu.py”文件“C:\Users\User\User\AppData\Local\Programs\Python\Python39\lib\site packages\pytube\\uuuuu main\uuuuuuuuuuuuu main.py”中的第91行,第183行,在预回迁self.js_url=extract.js_url(self.watch_html)文件“C:\Users\User\AppData\Local\Programs\Python39\lib\site packages\pytube\extract.py”中,第143行,在js_url base_js=get_ytplayer_config(html)[“assets”[“js”]键错误:“assets”

这是我的代码:

import os
from tkinter import *
from tkinter import filedialog
import tkinter as tk



root= Tk()
root.geometry('600x400')
root.title('Youtube Video Downloader')
root.configure(bg='gray')



Label_1=Label(root,text="Youtube video downloader", font=("bold",20), bg='gray')
Label_1.place(x=150,y=10)

Label_2=Label(root, text="Paste the link here", font=(10), bg='gray')
Label_2.place(x=240, y=75)



mylink=StringVar()

pastelink=Entry(root, width=60, textvariable=mylink)
pastelink.place(x=140, y=100)



def chooseDir():
    global path
    path = filedialog.askdirectory(title="Choose a download directory")
    videoLoc = path
    tk.Label(root, text=path, bg='gray').place(x=240,y=300)

def downloadVideo():
    ytbLink=str(mylink.get())
    ytbvideo=YouTube(ytbLink).streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
    ytbvideo.download(videoLoc)


    
def quitApp():
    root.destroy()
    



   

Button(root,text="Download video", width=20, bg='black',fg="white", command=downloadVideo).place(x=240, y=130)
Button(root,text="Choose location", width=20, bg='black',fg="white", command=chooseDir).place(x=240, y=160)
Label_3=Label(root, text="Curent location: ", font=("bold"), bg='gray')
Label_3.place(x=250, y=245)

Label_3=Label(root, text="by yakubiq", font=("bold"), bg='gray')
Label_3.place(x=0, y=375)

Button(root,text="Quit", width=20, bg='black', fg='white', command=quitApp).place(x=445, y=370)



root.mainloop()

我试图自己修复它,但我还是初学者,几天前就开始了。在控制台中,有第183行,但我不知道,这是什么意思

这个问题在较新版本的
pytube
上得到了修复,只需试着说
pip卸载pytube
,然后
pip安装pytube
,然后重新运行代码

就您的tkinter代码而言,您将
global
赋值给了错误的变量

def chooseDir():
    global videoLoc #correct globalization
    path = filedialog.askdirectory(title="Choose a download directory")
    videoLoc = path
    tk.Label(root, text=path, bg='gray').place(x=240,y=300)

def downloadVideo():
    ytbLink = mylink.get() #no need to use str() as it is string by default 
    ytbvideo = YouTube(ytbLink).streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
    ytbvideo.download(videoLoc)

通过这些更改,它应该可以工作,但请记住,在您给出的示例中,您没有导入pytube,因此它必须类似于pytube导入YouTube的
。尽管我也建议您使用
线程化

注释不是用于扩展讨论的;此对话已经结束。