【发布时间】:2020-07-13 13:11:35
【问题描述】:
from tkinter import *
from pytube import YouTube
root=Tk()
root.geometry("400x350")
root.title("Youtube video downloader application")
def download():
try:
myVar.set("Downloading...")
root.update()
Youtube(link.get()).streams.first().download()
link.set("Video download successfully")
except Expection as e:
myVar.set("Mistake")
root.update()
link.set("Enter correct link")
Label(root,text="Welcome to youtube\nDownloader Application",font="Consolas 15 bold").pack()
myVar=StringVar()
myVar.set("Enter the link below")
Entry(root,textvariable=myVar,width=40).pack(pady=10)
link=StringVar()
Entry(root, textvariable=myVar, width=40).pack(pady=10)
Button(root,text="Download video",command=download).pack()
root.mainloop()
这是我的代码,但是这段代码不起作用(程序完成 0)(在此之前我安装了 tkinter,pytube。)。我不知道如何重新编写这段代码。
【问题讨论】:
-
你在哪里调用你的
download()函数? -
@takendarkk 我相信倒数第二行
-
那是设置一个事件监听器。它实际上并没有调用该函数。在调用函数之前,该代码甚至不会执行。