当我尝试运行该程序并单击“下载”以下载youtube视频时,我总是得到:
AttributeError: 'builtin_function_or_method' object has no attribute 'get'
但我不知道为什么,这是我的完整代码,以防有用:
import tkinter as tk
import pytube
from tkinter import *
from pytube import YouTube
def handle_focus_in(_):
e.delete(0, tk.END)
e.config(fg='black')
def handle_focus_out(_):
e.delete(0, tk.END)
e.config(fg='grey')
e.insert(0, "Input Youtube URL")
def handle_enter(txt):
print(e.get())
handle_focus_out('dummy')
def click():
inp = input.get()
yt = YouTube(inp)
print(yt.streams.all())
stream = yt.streams.first()
stream.download()
root = tk.Tk()
b1 = Button(root, text="Download", fg="red", command=click)
b1.pack(side=BOTTOM)
e = tk.Entry(root, bg='white', width=30, fg='grey')
e.pack(side=TOP)
e.insert(0, "Input Youtube URL")
e.bind("<FocusIn>", handle_focus_in)
e.bind("<FocusOut>", handle_focus_out)
e.bind("<Return>", handle_enter)
root.title("Ayomide's Youtube Downloader")
root.configure(background="black")
root.mainloop()
出现此错误是因为
input
是Python的内置函数。让我们看看:https://www.w3schools.com/python/ref_func_input.asp此外,您没有定义
input
变量我已经检查了您的实现,我猜您希望从GUI获取
YouTube
链接并将其传递给YouTube()
类您应该将
inp = input.get()
更改为inp = e.get()
,在这种情况下inp
变量将包含来自GUI的YouTube URL我已经用以下方法对其进行了测试:
GUI:
控制台输出(如果我单击
Download
按钮):相关问题 更多 >
编程相关推荐