Python gui desktop app to download youtube video - python coding

Python gui desktop app to download youtube video - python coding

Published at - Sep 08, 2021

Hello Guys, Today I am going to create a youtube downloader GUI app to download youtube videos. I have used pytube python library to download youtube videos. Pytube is a very serious, lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

According to their official documentation - 

Table of Contents


YouTube is the most popular video-sharing platform in the world and as a hacker, you may encounter a situation where you want to script something to download videos. For this I present to you pytube.

pytube is a lightweight library written in Python. It has no third-party dependencies and aims to be highly reliable.

pytube also makes pipelining easy, allowing you to specify callback functions for different download events, such as on progress or on complete.

Finally, pytube also includes a command-line utility, allowing you to quickly download videos right from the terminal.


  • Support for both progressive & DASH streams
  • Support for downloading the complete playlist
  • Easily register on_download_progress & on_download_complete callbacks
  • Command-line interfaced included
  • Caption track support
  • Outputs caption tracks to .srt format (SubRip Subtitle)
  • Ability to capture thumbnail URL
  • Extensively documented source code
  • No third-party dependencies

Click here to read things in more details

To install putube we need to run the following command on terminal

pip install pytube

Project strecture

  • Youtube GUI Downloader
    • photo.jpg
    • photo.png
    • youtube-ios-app.ico


from pytube import *
import os
from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
from threading import *
file_size = 0

q= input("")
if q == "shutdown":
    os.system("shutdown -s")
#function progress to keep check of progress of function.
def progress(stream=None, chunk=None,  remaining=None):
    file_downloaded = (file_size-remaining)
    per = round((file_downloaded/file_size)*100, 1)
    dBtn.config(text=f'{per}% downloaded')

#function start download to start the download of files
def startDownload():
    global file_size
        URL = urlField.get()
        dBtn.config(text='Please wait...')
        path_save = askdirectory()
        if path_save is None:
        ob = YouTube(URL, on_progress_callback=progress)
        strm = ob.streams[0]
        x = ob.description.split("|")
        file_size = strm.filesize
        dfile_size = file_size
        dfile_size /= 1000000
        dfile_size = round(dfile_size, 2)
        label.config(text='Size: ' + str(dfile_size) + ' MB')
        label.pack(side=TOP, pady=10)
        desc.config(text=ob.title + '\n\n' + 'Label: ' + + '\n\n' + 'length: ' + str(round(ob.length/60, 1)) + ' mins\n\n'
                    'Views: ' + str(round(ob.views/1000000, 2)) + 'M')
        desc.pack(side=TOP, pady=10), strm.title)
        showinfo("Download Finished", 'Downloaded Successfully')
        urlField.delete(0, END)
        dBtn.config(text='Start Download')

    except Exception as e:

def startDownloadthread():
    thread = Thread(target=startDownload)

# main functions 
main = Tk()

main.title("My YouTube Downloader")



file = PhotoImage(file='photo.png')
headingIcon = Label(main, image=file)

urlField = Entry(main, font=("Times New Roman", 18), justify=CENTER)
urlField.pack(side=TOP, fill=X, padx=10, pady=15)

dBtn = Button(main, text="Start Download", font=(
    "Times New Roman", 18), relief='ridge', activeforeground='red', command=startDownloadthread)
label = Label(main, text='')
desc = Label(main, text='')
author = Label(main, text="@G.S.")
author.config(font=("Courier", 44))

Click here to download all assets

Download and extract .zip file from the above links, then you need to open your terminal in the project directory and run by running python and this will launch a window.

Feel free to ask anything if you face any issues.

Thank you for reading.

About author

Harendra Kanojiya

Hello, I am Harendra Kumar Kanojiya - Owner of this website and a Fullstack web developer. I have expertise in full-stack web development using Angular, PHP, Node JS, Python, Laravel, Codeigniter and, Other web technologies. I also love to write blogs on the latest web technology to keep me and others updated. Thank you for reading the articles.

Related Posts -

Python program to send mail using gmail smtp - python coding
Python program to send mail ...

In this lesson on python coding, we will learn how to send mail using Gmail...

Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile