Tkinter Youtube 下载管理器不起作用

发布于 2025-01-11 14:22:18 字数 1795 浏览 0 评论 0原文

我刚刚开始 tkinter 并制作现实生活中的项目。我想构建一个接收链接然后询问我们想要的分辨率的应用程序。最后它根据我们的分辨率下载视频。 粘贴链接后,选择分辨率并单击下载按钮,会出现如下错误:

AttributeError: 'NoneType' object has no attribute 'download' 我该怎么处理这个?

import tkinter as tk
from tkinter import filedialog
from pytube import YouTube 
import time
import os 

def showStreams(list):
    return list
def getStreams():
    yt = YouTube(entry.get())
    time.sleep(1)
    list = [stream.resolution for stream in yt.streams.filter(progressive=True)]
    
    for i in list:
        mb.menu.add_radiobutton(label=i, value=i, variable=selected_item)
    return selected_item

def download():
    file = filedialog.askdirectory(initialdir=os.path.dirname(__file__))
    yt = YouTube(entry.get())
    
    yt.streams.filter(res=str(selected_item)).first().download(file)

       
    

root = tk.Tk()
root.title("YouTube Download Manager")

canvas = tk.Canvas(root, height=400, width=400)
canvas.pack()

frame = tk.Frame(root, bg='#1EC3D5', bd=5)
frame.place(relx=0.5, rely=0.1, relwidth=0.7, relheight=0.1, anchor='n')

link = tk.StringVar()

entry = tk.Entry(frame, font=('Courier',10), textvariable=link)
entry.place(relwidth=0.65, relheight=0.95)

button =  tk.Button(frame, font=('Courier',10), text='Search', command=getStreams)
button.place(relx=0.7, relwidth=0.30, relheight=0.95)

middle_frame = tk.Frame(root, bg='#1EC3D5', bd=5)
middle_frame.place(relx=0.15, rely=0.22, relwidth=0.2, relheight=0.09)

selected_item = tk.StringVar()

mb=  tk.Menubutton(middle_frame, text="Choose!",font=('Courier',10) )
mb.place(relx=0.001,rely=0.001)
mb.menu =  tk.Menu(mb)
mb["menu"] =  mb.menu

download_button = tk.Button(root, text="Download", font=('Courier',10), bd=5, command=download)
download_button.place(relx=0.15, rely=0.3)


root.mainloop()

I just started to tkinter and making real life projects. I want to build an app that receives a link then asks for the resolution that we want. Finally it downloads the video according to our resolution.
After pasting the link, selecting the resolution and clicking the download button it gives an error like this:

AttributeError: 'NoneType' object has no attribute 'download'
how can I handle this ?

import tkinter as tk
from tkinter import filedialog
from pytube import YouTube 
import time
import os 

def showStreams(list):
    return list
def getStreams():
    yt = YouTube(entry.get())
    time.sleep(1)
    list = [stream.resolution for stream in yt.streams.filter(progressive=True)]
    
    for i in list:
        mb.menu.add_radiobutton(label=i, value=i, variable=selected_item)
    return selected_item

def download():
    file = filedialog.askdirectory(initialdir=os.path.dirname(__file__))
    yt = YouTube(entry.get())
    
    yt.streams.filter(res=str(selected_item)).first().download(file)

       
    

root = tk.Tk()
root.title("YouTube Download Manager")

canvas = tk.Canvas(root, height=400, width=400)
canvas.pack()

frame = tk.Frame(root, bg='#1EC3D5', bd=5)
frame.place(relx=0.5, rely=0.1, relwidth=0.7, relheight=0.1, anchor='n')

link = tk.StringVar()

entry = tk.Entry(frame, font=('Courier',10), textvariable=link)
entry.place(relwidth=0.65, relheight=0.95)

button =  tk.Button(frame, font=('Courier',10), text='Search', command=getStreams)
button.place(relx=0.7, relwidth=0.30, relheight=0.95)

middle_frame = tk.Frame(root, bg='#1EC3D5', bd=5)
middle_frame.place(relx=0.15, rely=0.22, relwidth=0.2, relheight=0.09)

selected_item = tk.StringVar()

mb=  tk.Menubutton(middle_frame, text="Choose!",font=('Courier',10) )
mb.place(relx=0.001,rely=0.001)
mb.menu =  tk.Menu(mb)
mb["menu"] =  mb.menu

download_button = tk.Button(root, text="Download", font=('Courier',10), bd=5, command=download)
download_button.place(relx=0.15, rely=0.3)


root.mainloop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文