36
loading...
This website collects cookies to deliver better user experience
arguments
called parameters
and can return results.def
keyword and a colon marks the beginning of the function block.In python indents are sensitive
def greetings(name):
print(f"Hello {name}!!")
# calling the function
greetings("Martin") # Hello Martin!!
tkinter
and pytube
.python -m pip install git+https://github.com/nficano/pytube
from tkinter import *
from pytube import YouTube
tkinter
to create the Graphical User Interface.root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title('Youtube Downloader')
link = StringVar()
Label(root, text = 'Paste Link Here: ', font='arial 15 bold').place(x=160, y=60)
text_box = Entry(root, width = 50, textvariable = link).place(x = 32, y = 100)
root
is a standard name used to initialize Tk()
as it is the base of the GUI.geometry()
function takes a string of the form widthxheight
, where width and height are measured in pixels for most widgets (in characters for widgets displaying text). For example: fred["geometry"] = "200x100".0, 0
make the Interface not resizable on both axis. A value more than 0 makes the axis resizable.Pytube
is used for downloading videos from YouTube.def download():
url = YouTube(str(link.get()))
video = url.streams.get_by_resolution("720p")
video.download()
Label(root, text = 'DOWNLOADED', font='arial 15').place(x=180, y=210)
Button(root,text = 'DOWNLOAD', font='arial 15 bold', bg='skyblue', padx = 2, command = download).place(x = 180, y = 150)
root.mainloop()
url
variable is an instance of the YouTube
object.video
variable stores 720p
resolution stream of the video to be downloaded.download
methods takes a number of arguments including output_path
. This is download storage location of the video. If the argument is not specified then the default is the current working directory.mainloop()
tells Python to run the Tkinter event loop. This method listens for events, such as button clicks or keypresses, and blocks any code that comes after it from running until the window it's called on is closed.