当我尝试运行该程序并单击“下载”时,我总是会下载:
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。
我已经使用以下方法对其进行了测试:
def click():
inp = e.get()
print("YouTube({})".format(inp))
GUI:控制台输出(如果我单击到
Download
按钮):>>> python3 test.py
YouTube(https://www.youtube.com/watch?v=7tN1EoUumHU)
关于python - AttributeError: 'builtin_function_or_method'对象没有属性 'get',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63299342/