Welcome to the Python Projects for Beginners Series 🙋🏻♂️
I'm Sai Ashish and today, we are going to code 5 Python Projects that can be built in under 5 minutes 🤯
I hope you're psyched because this is going to be amazing 💯
1. Notification Generator 🔢 2. Check Your Battery Percentage 🔋 3. Take a Screenshot 🖼 4. Figlet Generator 🔠 5. ConvertText to Speech 🗣
1. How to effectively use modules in our python programs 2. Basics of Python: Functions
As the name suggests, a notification generator generates a notification(a message) about a particular task, reminder or anything you require. In today's build, we would be generating a pop-up notification on a Windows device.
Apart from the obvious, you can integrate this snippet of code into any of your applications. For example, in How to Build an Alarm Clock using Python, you can also generate a notification along with your favourite song. Or suppose you wanted to get an alert whenever your battery percentage is below 35 or get reminders, this is the tool for you.
For this build, we require the win10toast module. win10toast is an easy-to-use Python library for displaying Windows 10 Toast(Pop-up) Notifications. The official document of the module can be accessed from here.
To install the win10toast module, go to the terminal and run,
pip install win10toast
That's it. You're all ready for the build now.
The first step is to import the win10toast module into our programming environment. For this, we use the import statement as,
from win10toast import ToastNotifier
Next, we define a function named windows_popup that takes three parameters as input — title, content and duration.
Functions help break our program into smaller and modular chunks. Moreover, it avoids repetition and makes the code reusable.
In our function, we code two statements,
We create an instance of the ToastNotifier class and store it inside toast variable. Imagine the instance as a remote control to your program. You can now use any buttons on the remote control to perform the task needed.
We call the show_toast function and pass the input parameters as seen.
title: the title of the notification. it appears in bold. Example: Reminder
content: the content of the notification. Example: Close down your desktop and go for a walk!
duration: the duration in seconds you want the notification to be shown on the screen
Finally, we call the function as:
windows_popup("Reminder", "Go and get a life!")
You can directly download the source code for Notification Generator from my Github Respository.
In this build, we generate the battery percentage of our device.
For this build, we use the psutil module. psutil is a cross-platform library for process and system monitoring in Python. The official documentation of the psutil module can be found here.
To install psutil into our system, type in the terminal the following:
pip install psutil
As always, import the psutil module into our environment.
Gain the remote control by creating an instance of the sensors_battery() class in the psutil module.
battery = psutil.sensors_battery()
Gain the battery percentage information into variable percent as follows:
percent = str(battery.percent)
To display the battery percent on the screen, type:
print("Battery Percent= " + percent + "%")
You can directly download the Battery Percentage Checker code from my Github Repository too.
To test your coding skills, try generating a notification when the battery percentage falls below 35%. Comment your code in the comment box below!
For this build we require the Pyautogui and the time module.
PyAutoGUI is a python module that lets you control your mouse and keyboard using a program. PyAutoGUI also lets you automate your everyday tasks and can play games, login into emails, and more. You can access the official documentation of Pyautogui module from here.
To install PyAutoGUI in your system, open your terminal and run:
pip install pyautogui
The time module provides various time-related functions. We use it to retrieve the system time and display it on the screen. You can access the official documentation from here
Importing the required modules into our python environment:
import pyautogui import time
We use the time.sleep method to switch the application from our python environment to the screen we want to take a screenshot from.
To take the screenshot, we use pyautogui's screenshot method and store it inside the img variable.
img = pyautogui.screenshot()
To save the image, we use the save method as:
Note: This command will save the image into the same directory as the location of the python file you're running from.
You can directly download the source code of the Screenshot Taker build from here.
The Figlet Generator Converts ordinary text into a creative figure letter design(ASCII Art Font) as shown below:
For this build, we require the PyFiglet module. You can access the official documentation of Pyfiglet module from here. The PyFiglet module can be installed by using:
pip install pyfiglet
The first step, is to import the Pyfiglet module
To convert your word into ASCII Block Art format we use the figlet_format function. We store the result into a variable called result. For slant font, we set the fomn to slant. For normla block, just omit that paramter and enter only the text in double quotes.
result = pyfiglet.figlet_format("Sai Ashish", font = "slant")
Display your creativity using thr print statement:
You can directly download the source code from my Github Repository.
Last but not the last and my most favorite build among all, the Text to Speech Generator.
For this amazing build, we require the pyttsx3 module. pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3.You can check the official documentation from here
To install pyttsx3 into our system, go to the terminal and type:
pip install pyttsx3
We import the pyttsx3 module into our environment using:
To get the remote control, we initialise pyttsx3 as:
engine = pyttsx3.init()
After gaining the instance, we use the say method to tell the engine to speak the sentence provided to it.
Finally, we use the runAndWait command to run the command.
You can directly download the Text to Speech Build from my Github Repository.
That's it, folks! We have successfully learnt 5 short yet interesting builds that can be implemented in under 5 minutes. These builds are a very good stepping step for any beginner in Python. If this blog provided value to you smash the like button and subscribe to the newsletter to never miss another blog update 💯
Bonus Insights by The Insightful Coder :
Interested in Building Your Own Artificial Intelligence Projects using Python?: Check out the Python AI Series🧠
Wanna Discover Some Valuable Tech-Hacks 🛠?: Check out the Tech-Hacks for Everybody Series😎
I'm also dropping daily value bombs and development insights on my Instagram Page. Make sure to follow me up 💯
Find and Download All My Project Source Codes at My Github Repository 🎁