build a youtube downloader with python gui

Solutions on MaxInterview for build a youtube downloader with python gui by the best coders in the world

showing results for - "build a youtube downloader with python gui"
Guadalupe
23 Sep 2020
1
2# importing tkinter
3from tkinter import *
4# importing YouTube module
5from pytube import YouTube
6# initializing tkinter
7root = Tk()
8# setting the geometry of the GUI
9root.geometry("400x350")
10# setting the title of the GUI
11root.title("Youtube video downloader application")
12# defining download function
13def download():
14    # using try and except to execute program without errors
15    try:
16        myVar.set("Downloading...")
17        root.update()
18        YouTube(link.get()).streams.first().download()
19        link.set("Video downloaded successfully")
20    except Exception as e:
21        myVar.set("Mistake")
22        root.update()
23        link.set("Enter correct link")
24
25# created the Label widget to welcome user
26Label(root, text="Welcome to youtube\nDownloader Application", font="Consolas 15 bold").pack()
27# declaring StringVar type variable
28myVar = StringVar()
29# setting the default text to myVar
30myVar.set("Enter the link below")
31# created the Entry widget to ask user to enter the url
32Entry(root, textvariable=myVar, width=40).pack(pady=10)
33# declaring StringVar type variable
34link = StringVar()
35# created the Entry widget to get the link
36Entry(root, textvariable=link, width=40).pack(pady=10)
37# created and called the download function to download video
38Button(root, text="Download video", command=download).pack()
39# running the mainloop
40root.mainloop()
41