Simple python based GUI application to download YouTube videos.

Rohit Shubankar
Analytics Vidhya
Published in
4 min readFeb 15, 2020

In this tutorial, I am going to show you how to build a GUI app that can download videos from YouTube. We are going to use tkinter package for developing our GUI and youtube-dl to download the video from YouTube.

The basic idea is that the app consists of a text bar where the user enters the URL of the video and then clicks on the “Download” button which then downloads the video. The app shows a message when the download is complete.

First, we start by loading the required packages:

Now that we have our required packages loaded successfully, we start by creating our GUI app. We initialize tkinter by creating a root widget, which is a frame/window where we are going to attach our buttons and the text bar. Please remember that there can be only one root widget and it has to be created before any other widgets.

Now, to change the title and the icon image in the title bar :

We can set the dimensions of our window:

If you have followed the above steps correctly, just add root.mainloop() at the end of your code and run the program. We use the mainloop() method when we want to run our program. You will get a window as displayed below:

Lets add a canvas to our window. Canvas is a rectangular area where we can place our text and widgets. In the below line of code, we are attaching our canvas to the root window or the parent window and we give the same dimensions as our root window. We also give a background color to our canvas.

If we run the program now, we may get something like this:

Now, lets add a text in our canvas. We create a label which basically allows us to display text and images. User cannot interact with the labels but can just view it.

Let’s run the program.

We will create a text bar / search bar where the user can enter the URL to download the video. We use the Entry widget to enter and display single line of text.

We will get something like this:

Let’s create a function which downloads the video from YouTube. We make use of the youtube-dl package for downloading the video. We get the user entered URL by using the get().

We now create another text in our canvas, which tells the user that the video has been downloaded. This will be displayed after our video has been downloaded.

Now it’s time to create the button which when clicked will direct to the user entered URL and will download the video from YouTube. We use the button widget which has parameters like text, background color, command etc. Command is used to link the function which will be performed when we click the button.

Finally, when we run the program:

And when the video gets downloaded:

Well here you go. You have just created an GUI application that can download YouTube videos.

The code described above is available in my Github account :

If anyone has any questions/comments feel free to contact me here or by mail: rohit.shubankar@gmail.com

Thank you

--

--