{"id":83171,"date":"2021-07-27T09:00:22","date_gmt":"2021-07-27T03:30:22","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83171"},"modified":"2026-06-03T16:02:47","modified_gmt":"2026-06-03T10:32:47","slug":"youtube-video-downloader-in-python","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/","title":{"rendered":"YouTube Downloader With Python &amp; Pytube"},"content":{"rendered":"<p>In this Python project, we will build a GUI-based YouTube Video Downloader using the Tkinter and pytube modules of Python. It is a beginner-level project, and you will get to apply some cool libraries in real-life. Let\u2019s get started!<\/p>\n<h3>About YouTube Video Downloader:<\/h3>\n<p>Aren\u2019t there a lot of YouTube videos you wished you could\u2019ve watched without the internet on your laptops or desktops?<\/p>\n<p>Well, here\u2019s your solution. In this project, we will create a YouTube video downloader where you can download the video straight from YouTube to your laptop.<\/p>\n<h3>About the YouTube Video Downloader project in Python:<\/h3>\n<p>The objective of this is to create a GUI based YouTube Video Downloader. To build this, you will need a little understanding of Tkinter and pytube. This project is very good and it solves a problem pertinent to most.<\/p>\n<h3>Project Prerequisites:<\/h3>\n<p>To build this Python YouTube Video Downloader project, we will need the following libraries:<\/p>\n<p><strong>1. Tkinter &#8211;<\/strong> To create the GUI<br \/>\n<strong>2. pytube.YouTube &#8211;<\/strong> To download the videos<\/p>\n<p>Since the pytube library does not come pre-installed with Python, you will have to run the following command to install it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python -m pip install pytube<\/pre>\n<p>Python wrapper is used because some computers do not allow the pip command alone.<\/p>\n<h3>Download YouTube Downloader Python Project<\/h3>\n<p>Please download the source code of python youtube downloader: <a href=\"https:\/\/drive.google.com\/file\/d\/1m20fDqV65gdmLIkNWGLUKLpP6D6pBnnn\/view?usp=drive_link\"><strong>YouTube Downloader Python Code<\/strong><\/a><\/p>\n<h3>Project File Structure:<\/h3>\n<p>Here are the steps you will need to execute to build this Python YouTube Video Downloader Project:<\/p>\n<p>1. Importing all the necessary imports<br \/>\n2. Creating the download and reset buttons functions<br \/>\n3. Initializing the window and placing all its components<\/p>\n<p>Let\u2019s take a closer look at these steps:<\/p>\n<h4>1. Importing all the necessary modules:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Importing all the necessary modules for Python YouTube Video Downloader project\r\nfrom tkinter import *\r\nfrom tkinter import messagebox as mb\r\nfrom pytube import YouTube<\/pre>\n<h4>2. Creating the download and reset buttons functions:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Defining the downloader function for YouTube Video Downloader project using Python\r\ndef downloader(link, directory, filename):\r\n    yt_link = link.get()\r\n    save_path = directory.get()\r\n    aftersave_filename = filename.get()\r\n\r\n    try:\r\n        yt = YouTube(yt_link)\r\n        video = yt.streams.first()\r\n        video.download(save_path, aftersave_filename)\r\n    except:\r\n        mb.showerror('Error', 'Connection Error! You are offline!')\r\n\r\n\r\ndef reset(l_strvar, d_strvar, fn_strvar):\r\n    l_strvar.set('')\r\n    d_strvar.set('')\r\n    fn_strvar.set('')\r\n<\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>We have created the <strong>download()<\/strong> function to make use of the YouTube class to download the YouTube videos.\n<ul>\n<li>We will give the function 3 parameters, all of which should be Entry objects controlled by StringVar objects. Then we will initially get the text from the Entry objects and assign it to variables.<\/li>\n<li>Then we will use the try &#8230; except statements to make sure that when we initialize the YouTube class, the user has an active internet to download the videos, or else we will print an error message.<\/li>\n<\/ul>\n<\/li>\n<li>In the <strong>reset()<\/strong> function, we will set the 3 StringVar objects that are provided as arguments, that control the 3 Entry objects, as blank strings so the values in Entry objects also become blank.<\/li>\n<\/ul>\n<h4>3. Initializing the window and placing all its components:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Initializing the window\r\nroot = Tk()\r\nroot.title('TechVidvan Youtube Video Downloader')\r\nroot.geometry('700x200')\r\nroot.resizable(0, 0)\r\nroot.config(bg='Coral')\r\n\r\n# Heading label\r\nLabel(root, text='TechVidvan Youtube Video Downloader', font=(\"Comic Sans MS\", 15), bg='Coral').place(relx=0.25, rely=0.0)\r\n\r\n# Creating the main window\r\nLabel(root, text='Enter the Youtube link:', font=(\"Times New Roman\", 13), bg='Coral').place(relx=0.05, rely=0.2)\r\n\r\nlink_strvar = StringVar(root)\r\nlink_entry = Entry(root, width=50, textvariable=link_strvar)\r\nlink_entry.place(relx=0.5, rely=0.2)\r\n\r\n\r\nLabel(root, text='Enter the save location:', font=(\"Times New Roman\", 13), bg='Coral').place(relx=0.05, rely=0.4)\r\n\r\ndir_strvar = StringVar(root)\r\ndir_entry = Entry(root, width=50, textvariable=dir_strvar)\r\ndir_entry.place(relx=0.5, rely=0.4)\r\n\r\n\r\nLabel(root, text='Enter the filename:', font=(\"Times New Roman\", 13), bg='Coral').place(relx=0.05, rely=0.6)\r\n\r\nfilename_strvar = StringVar(root)\r\nfilename_entry = Entry(root, width=50, textvariable=filename_strvar)\r\nfilename_entry.place(relx=0.5, rely=0.6)\r\n\r\n# Creating the buttons\r\ndownload_btn = Button(root, text='Download', font=7, bg='Aquamarine',\r\n                      command=lambda: downloader(link_entry, dir_entry, filename_entry)).place(relx=0.3, rely=0.75)\r\n\r\nreset_btn = Button(root, text='Reset', font=7, bg='Aquamarine',\r\n                   command=lambda: reset(link_strvar, dir_strvar, filename_strvar)).place(relx=0.5, rely=0.75)\r\n\r\n# Finalizing the window of Python YouTube Video Downloader project\r\nroot.update()\r\nroot.mainloop()<\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>Now, we will use the <strong>Tk()<\/strong> class to initialize the GUI window.\n<ul>\n<li>The <strong>.title()<\/strong> method is used to set a title to the window.<\/li>\n<li>The <strong>.geometry()<\/strong> method is used to specify the initial geometry of the window.<\/li>\n<li>The <strong>.resizable()<\/strong> method, which takes truthy and falsy values as arguments, is used to allow\/deny the permission to resize the window. It\u2019s positional arguments are taken in the form (width, height).<\/li>\n<li>The <strong>.configure()<\/strong> method is used to define the other attributes of the Tk class, such as bg which sets the background color to the window.<\/li>\n<li>The <strong>.update()<\/strong> and <strong>.mainloop()<\/strong> methods are used to put the window in a loop so that the window does not close as soon as it opens.<\/li>\n<\/ul>\n<\/li>\n<li>The <strong>Label<\/strong> class is used to add static text to the window. Its parameters and methods are:\n<ul>\n<li>The <strong>master<\/strong> parameter, the positional argument root in this case, is the parent widget it is associated with.<\/li>\n<li>The <strong>text<\/strong> parameter is the text that will be displayed on the widget.<\/li>\n<li>The <strong>font<\/strong> parameter is the font family and size and text effects of the text in the widget.<\/li>\n<\/ul>\n<\/li>\n<li>The <strong>Button<\/strong> class is used to add a button to the window that runs a function when pressed. Its parameters and methods are:\n<ul>\n<li>The <strong>command<\/strong> parameter defines the function that will run when the button is pressed. You will not need to use the lambda keyword if the function to run does not need any arguments.<\/li>\n<\/ul>\n<\/li>\n<li>The <strong>Entry<\/strong> class is used to add an input field to the window, which allows the user to input data. Its parameters and methods are:\n<ul>\n<li>The <strong>width<\/strong> parameter is used to mention the number of characters that will fit in the widget.<\/li>\n<li>The <strong>.get()<\/strong> method is used to get the text inputted by the user in the Entry widget. It takes no arguments.<\/li>\n<\/ul>\n<\/li>\n<li>The <strong>StringVar<\/strong> class is used to manipulate text in Label and Entry widgets. Its methods are:\n<ul>\n<li>The <strong>.set()<\/strong> method is used to set a value to the StringVar object and the widget it manipulates. The only argument it takes is the text that the value has to be set to.<\/li>\n<\/ul>\n<\/li>\n<li>The <strong>.place()<\/strong> method, which is one of the 3 Tkinter geometry manager methods, positions a widget such that it is placed on a Cartesian Plane.\n<ul>\n<li>The x, y parameters denote the horizontal and vertical offsets of the widget.<\/li>\n<li>The<strong> relx, rely<\/strong> parameters are the horizontal and vertical offsets of the widget in terms of a floating number between 0.0 and 1.0<\/li>\n<li>The <strong>anchor<\/strong> parameter defines the corner or side of the window that will be considered as the origin of the cartesian plane that is our window.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Python YouTube Downloader Output<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/python-youtube-downloader-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83754\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/python-youtube-downloader-output.png\" alt=\"python youtube downloader output\" width=\"874\" height=\"286\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Congratulations! You have now created your own GUI-based YouTube Video Downloader using the Tkinter and pytube modules in Python. Now you will be able to download YouTube videos on your laptop without any hassles. There are many more changes that you can make to this project, and this will be more amazing! Have fun coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python project, we will build a GUI-based YouTube Video Downloader using the Tkinter and pytube modules of Python. It is a beginner-level project, and you will get to apply some cool libraries&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83755,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[483,3876,3877,3878],"class_list":["post-83171","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-project","tag-python-youtube-downloader","tag-python-youtube-video-downloader","tag-youtube-downloader"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>YouTube Downloader With Python &amp; Pytube - TechVidvan<\/title>\n<meta name=\"description\" content=\"Create your own YouTube Video Downloader using Tkinter and pytube modules in Python &amp; download YouTube videos on laptop without any hassles.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"YouTube Downloader With Python &amp; Pytube - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Create your own YouTube Video Downloader using Tkinter and pytube modules in Python &amp; download YouTube videos on laptop without any hassles.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-27T03:30:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-03T10:32:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/python-project-youtube-video-downloader.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"YouTube Downloader With Python &amp; Pytube - TechVidvan","description":"Create your own YouTube Video Downloader using Tkinter and pytube modules in Python & download YouTube videos on laptop without any hassles.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/","og_locale":"en_US","og_type":"article","og_title":"YouTube Downloader With Python &amp; Pytube - TechVidvan","og_description":"Create your own YouTube Video Downloader using Tkinter and pytube modules in Python & download YouTube videos on laptop without any hassles.","og_url":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-07-27T03:30:22+00:00","article_modified_time":"2026-06-03T10:32:47+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/python-project-youtube-video-downloader.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"YouTube Downloader With Python &amp; Pytube","datePublished":"2021-07-27T03:30:22+00:00","dateModified":"2026-06-03T10:32:47+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/"},"wordCount":918,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/python-project-youtube-video-downloader.jpg","keywords":["Python project","python youtube downloader","Python YouTube Video Downloader","youtube downloader"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/","url":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/","name":"YouTube Downloader With Python &amp; Pytube - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/python-project-youtube-video-downloader.jpg","datePublished":"2021-07-27T03:30:22+00:00","dateModified":"2026-06-03T10:32:47+00:00","description":"Create your own YouTube Video Downloader using Tkinter and pytube modules in Python & download YouTube videos on laptop without any hassles.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/python-project-youtube-video-downloader.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/python-project-youtube-video-downloader.jpg","width":1200,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/youtube-video-downloader-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"YouTube Downloader With Python &amp; Pytube"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83171"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83171\/revisions"}],"predecessor-version":[{"id":448168,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83171\/revisions\/448168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83755"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}