Tkinter Youtube 下载管理器不起作用
我刚刚开始 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论