Python YouTube Video Downloader:

Meta-Description:

YouTube videos are a great way to learn new things, so follow along with this tutorial to create a video downloader so you can watch your favourite videos whenever you like!

Introduction: 

With so much information, entertainment, and educational material online, watching videos is a great way to learn more about specific topics of interest. However, it can be hard to watch these videos if you happen to have a slow or intermittent internet connection, as it can cause videos to buffer or lag. 

Python YouTube Video Downloader

That’s why in this article we are going to be using Python to create a YouTube video downloader that can be used to download our favourite YouTube videos directly to your computer. This will allow you to watch them directly from your device, making them accessible at all times. Whether you are new to Python or have some prior experience, this project is a great way to learn more about making functional programs and helps you apply your knowledge in a practical and fun way, and is a great beginner Python project for kids.

Who is this Project For?

This is an intermediate-level project for those who are new to Python. At this point, you should already know the basics of creating functions, installing packages, and creating simple GUIs (graphical user interfaces) with Tkinter. These are the concepts that you will use and build upon as you code this project.

What Will We Learn?

This video downloader project focuses on using the Tkinter library to create the program’s GUI, as well as the Pytube library to download videos directly from YouTube. Both of these libraries are very versatile and can be used for a wide variety of projects, making this project a great way to learn new skills that can be used later on for even more projects. 

Features to Consider:

Python YouTube Video Downloader

Main Steps:

This project can be broken down into 4 main steps: 

  1. Import and setup modules
  2. Create the main Tkinter GUI
  3. Define the Downloader function
  4. Create the GUI’s ‘Download’ button

Step 1: Import the Modules:

The first thing we’ll need to do to begin the project is import all of the libraries and modules that we’ll be using. Because the Tkinter and Pytube libraries are non-native, meaning that they must be installed and imported to the computer before being used. The first step we will need to do is install these libraries on the device. To do this, you can open the command line on your computer and type the command:

pip install tkinter
pip install pytube

Now that the libraries have been set up, it’s time to import them into the program. This will let the program know that we will be using these libraries. The code for this step will look like this:

from tkinter import *
from pytube import YouTube

Step 2: Create the main Tkinter GUI

Now that all of the modules have been imported, it’s time to create the program’s graphical user interface. This will involve setting up the canvas and its dimensions, titling the window, and adding a text input box. To begin, we’ll initialize Tkinter and create the window. Our window will be 500x300 pixels so we will set these as the dimensions. After this is done, the code will be:

root = Tk()
root.geometry('500x300')

Now we’ll need to set up the window so that it cannot be resized. This will prevent the elements such as titles, buttons, and text inputs from being shifted around and resized. We will also title the window so that users know exactly what it’s called. In this case, we’re titling the window “Geekedu Video Downloader”. Once this step is complete, the code should look like this:

root.resizable(0, 0)
root.title('Geekedu Video Downloader')

Next, it’s time to create labels for the GUI, as well as create the text input box. We’ll start by creating a label to let users know what the program does. To do this, we will create a label that says “YouTube Video Downloader” and place it at the top center of the window. Underneath, we will also create another label that says “Paste Link Here:” to let users know where to insert the video link. The code for this step of the project will be:

Label(root,text = 'YouTube Video Downloader', 
font ='arial 20 bold').pack()
Label(root, text = 'Paste Link Here:', 
font = 'arial 15 bold').place(x= 160 , y = 60)

Hint: There is a set format that is used for creating labels with the Tkinter GUI. The format is as follows: Label(root, text = 'Add Label Text Here', font = 'font font size style').place(x= X-coordinate , y = Y-coordinate). Note that any section in bold will be replaced with the desired text, format, or coordinates for the label.

Now that the labels for the GUI are complete, it’s time to add the text input box. To start, we’ll create a variable called “link”, and set it to a blank string variable. 

Hint: This will let the program know that the text entered into the text box will be a string, and the computer can take this information and store it as a variable.

Next, we’ll create a text box where users can paste their video’s link. This element will follow  a very similar format to the labels we created earlier, and in the end, the code will look like this:

link = StringVar()
link_enter = Entry(root, width = 45,
textvariable = link).place(x = 32, y = 90)

Once this step is complete, the main GUI is finished and it’s time to move on to code the main download function of the program.

Python YouTube Video Downloader

Step 3: Define the Download Function

Now we’ll move on to create the download function. This function will take the link that users input in the text box, download the video, and display the message to let users know that the download was successful. The first section of code for this step of the program will look like this:

def Downloader():
    url =YouTube(str(link.get()))
    video = url.streams.first()
    video.download()

As you can see in the code, we’ve started by defining the initial Downloader function. Then, we used two more lines of code to get the user’s input, and essentially let the program know that the link is the video that should be downloaded. Finally, we added a line of code to download the video to your device, which will allow you to play the video even without an internet connection. 

Python YouTube Video Downloader

Finally, we need to add the downloaded message. To do this, we will add a label that displays a “Downloaded” message. The code for this step will be:

Label(root, text = 'DOWNLOADED', 
font = 'arial 15').place(x= 180 , y = 210)

Step 4: Create the GUI’s ‘Download’ Button

Finally, we just need to add the ‘Download’ button to the GUI, as well as a line of code to run the whole project. We will use the same basic formatting as was previously used for the labels and input box to create a button. Finally, we will use the root.mainloop() command to set up the program and allow it to be run. This command will essentially run the pain Python file and loop it forever, which means the program will always run. Once this final step is complete the code will look like this:

Button(root,text = 'DOWNLOAD', 
font = 'arial 15 bold' ,bg = 'pale violet red', padx = 2, 
command = Downloader).place(x=180 ,y = 150)
root.mainloop()

Python YouTube Video Downloader

Hint: Note that in the line of code where we set up the Download button, the format is slightly different as we added colour as well as padding and a command. Here are the main elements of this formatting:

Project Complete!

Python YouTube Video Downloader

And now the project is complete! At this point, you will be able to use the YouTube video downloader to download videos so you can watch them offline. Hopefully, you’ve enjoyed this beginner Python tutorial for kids, and if you’re stuck or have any issues with your code, try reviewing it again either in your text editor or by looking at the code mentioned above as a reference. 



Python Alarm Clock:

Meta-Description:

It’s the time of year where students go back to school, so what better time to practice coding by creating an alarm clock that can wake you up in the morning!

Introduction: 

In this article, we are going to be creating an alarm clock that can be used for a variety of purposes, from waking you up in the morning to alerting you at a specific time. The project will allow users to use a menu to select a time for their alarm to go off, then will alert them at the correct time. Whether you are new to Python or have some prior experience, this project is a great way to learn more about making functional programs and helps you apply your knowledge in a practical and fun way.

Who is this Project For?

This is an intermediate-level project for those who are new to Python. At this point, you should already know the basics of creating functions, installing packages, and creating simple GUIs (graphical user interfaces) with Tkinter. These are the concepts that you will use and build upon as you code this project.

What Will We Learn?

This project focuses on using the Tkinter library to create the program’s GUI, as well as the datetime, time, and playsound modules to set an alarm and generator notifications. This is a relatively simple project that has a wide variety of uses, so let’s get started!

Features to Consider:

Main Steps:

This project can be broken down into 4 main steps: 

  1. Import modules
  2. Create the Tkinter GUI
  3. Create the GUI’s menus, buttons, and frames
  4. Define the alarm function
Python Alarm Clock

Step 1: Import Modules:

The first thing we’ll need to do to begin the project is import all of the libraries and modules that we’ll be using. We will use the Tkinter library for the graphics, and the datetime, time, and playsound modules to create the alarm and sound effects. We will also use threading to allow the computer to run multiple sections of code at once. First, you’ll need to import the libraries we need and initialize the Tkinter window. To do this, we’ll type: 

from tkinter import *
import datetime
import time
import playsound
from threading import *
Hint: If you haven’t already downloaded these packages to your computer you can do it using the command line and the “pip install” command.

Step 2: Create the Tkinter GUI

Now that all of the modules have been imported, it’s time to initialize Tkinter and create the program’s graphical user interface. We’ll start by initializing Tkinter and setting up a window for the alarm. To do this, you will type:

root = Tk()
root.title("Geekedu Alarm Clock")
root.geometry("400x200")

Next, we need to use threading so that the program can run multiple sections of code at once. To do this we will create a function called “Threading” and set it up so that the code can handle multiple aspects of the code at the same time in order to make the program work better. This will help us ensure that the timing of the alarm works well and is accurate. The code for this section will be:

def Threading():
	t1=Thread(target=alarm)
	t1.start()

Step 3: Create the GUI’s Menus, Buttons, and Frames 

Now that the GUI is set up, it’s time to move on to add frames, labels, and buttons to the GUI.  We’ll start by creating two simple labels: “Alarm Clock” and “Set Time:”. These labels will be centered in the window and will let users know what the program is and how to interact with it. Next, we’ll create a widget using a StringVar to store all of the hour values that users can choose from. Because the clock uses 24-hour time, these will be the values from 0-24. 

Python Alarm Clock

We will also set the default hour value to 0 until the user selects a different time. The code for this step will be:

Label(root,text="Alarm Clock",font=("Helvetica 20 bold"),fg="red")
.pack(pady=10)
Label(root,text="Set Time:",font=("Helvetica 15 bold")).pack()

frame = Frame(root)
frame.pack()

hour = StringVar(root)
hours = ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09'
, '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'
, '21', '22', '23', '24')
hour.set(hours[0])

Hint: You may want to format the widget to make sure it’s in the correct location. To do this, you can type:
hrs = OptionMenu(frame, hour, *hours)
hrs.pack(side=LEFT)

Next we’ll make two more widgets- one for the minutes and one for the seconds. These will also be formatted using Tkinter the same way we just formatted the hours. By the end of this step your code should look like this:

minute = StringVar(root)
minutes = ('00', '01', '02', '03', '04', '05', '06', '07',
		'08', '09', '10', '11', '12', '13', '14', '15',
		'16', '17', '18', '19', '20', '21', '22', '23',
		'24', '25', '26', '27', '28', '29', '30', '31',
		'32', '33', '34', '35', '36', '37', '38', '39',
		'40', '41', '42', '43', '44', '45', '46', '47',
		'48', '49', '50', '51', '52', '53', '54', '55',
		'56', '57', '58', '59', '60')
minute.set(minutes[0])
mins = OptionMenu(frame, minute, *minutes)
mins.pack(side=LEFT)

second = StringVar(root)
seconds = ('00', '01', '02', '03', '04', '05', '06', '07',
		'08', '09', '10', '11', '12', '13', '14', '15',
		'16', '17', '18', '19', '20', '21', '22', '23',
		'24', '25', '26', '27', '28', '29', '30', '31',
		'32', '33', '34', '35', '36', '37', '38', '39',
		'40', '41', '42', '43', '44', '45', '46', '47',
		'48', '49', '50', '51', '52', '53', '54', '55',
		'56', '57', '58', '59', '60')
second.set(seconds[0])
secs = OptionMenu(frame, second, *seconds)
secs.pack(side=LEFT)

Python Alarm Clock

Finally, we’ll just add a “set alarm button using this line of code:

Button(root,text="Set Alarm"
,font=("Helvetica 15"),command=Threading).pack(pady=20)

Once this final step is complete, we’re finished with the GUI and it’s time to move on to creating the alarm function!

Step 4: Define the Alarm Function

Now that the GUI has been completed, it’s time to create the alarm function. Start by defining a function called “alarm”, and then creating a while statement. We will use this statement to take input from the hour, minute, and second widgets, and then we’ll use a timer.sleep command to make the program wait 1 second. At this point, the code should look like this:

def alarm():
	while True:to
		set_alarm_time = f"{hour.get()}
:{minute.get()}:{second.get()}"
		time.sleep(1)

Next, we’ll add a line of code to take the computer’s local time and compare it with the set alarm time like so. This will be done using the datetime module.

current_time = datetime.datetime.now().strftime("%H:%M:%S")
		print(current_time,set_alarm_time)

And now there are only a few lines left to code! At this point, we just need to create an if-statement to check if the times are the same, as well as a command to execute Tkinter. Let’s start by creating an if-statement to check if the current time is equal to the alarm time. If so, we want to print “time to wake up”, and play the alarm sound.

Hint: You may need to download an alarm sound and add it to your program’s files. Then, you can simply use the command playsound(“alarmName.wav”) to play the sound. 
Python Alarm Clock

At the very end, we’ll just add a command to execute the Tkinter code and we’re done! Now that the project is finished, the code should be:

if current_time == set_alarm_time:
			print("Time to Wake up")
			playsound('alarm.wav')
root.mainloop()

Project Complete!

And now the project is complete! At this point, you will be able to use this alarm clock to alert you about events at specific times or to wake you up after a nap. Feel free to test your code now and see how it works. If you’re stuck or have any issues with your code, try reviewing it again either in your text editor or by looking at the code mentioned above as a reference. 


Geekedu’s curriculum is great to teach. It’s structured and organized but allows me to form a connection with my students. It’s great to be able to explain concepts in ways that students can understand. Geekedu makes math more than an abstract concept. It’s a valuable way for kids to see and understand the world.”

Instructor Emma