python - AttributeError: 'builtin_function_or_method'对象没有属性 'get'

标签 python tkinter youtube attributeerror pytube

当我尝试运行该程序并单击“下载”时,我总是会下载:

    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:
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/

相关文章:

python - 与词法作用域和 for 循环作斗争

youtube - 在网页上显示youtube播放列表标题

machine-learning - Python 机器学习数据集中的类名存储在哪里?

python-3.x - Python 3 和 Tkinter 有问题且缓慢

python - 如何为 href 指定方法名称?

python - 从 mplfinance 重新绘制 Candlestick_ohlc 的最有效方法

ios - 无法在 UIWebView 中播放 Youtube 视频(iOS、Swift)

android - Android-Youtube Player在指定时间停止视频

python - 强制加载 `None` 并在转储时跳过 `None`

python - 将 Pandas Dataframe 转换为带有逗号的 float 时出错