Let’s build a project that tells your laptop or computer battery is how much charged i.e, a Desktop Battery Notifier in Python using psutil and plyer library notification.
This project is best to add in your resume if your are a fresher or you want internships.
How Does This Desktop Battery Notifier in Python Work?
This small Python script checks your laptop’s battery level and shows a pop-up notification based on certain conditions. It tells you:
When your battery is low.
When it’s fully charged.
When it’s charging but not yet full.
When it’s time to unplug the charger for better battery life.
What Do We Need to build this Desktop Battery Notifier?
To build this project, we use two Python libraries:
<em><strong>plyer</strong></em>
: It shows desktop notifications.<strong><em>psutil</em></strong>
: It helps get battery information like percentage and charging status.
You can install both using pip if they are not already available.
Main Logic Behind the Notifier
The logic is quite easy to understand. The script runs and checks two things: Battery percentage and whether the charger is plugged in or not.
Then, depending on these two factors, it shows different messages. For example:
- If the charger is plugged in and the battery is 100%, it notifies you to unplug.
- If the charger is plugged in and battery is below 80%, it reminds you to charge more.
- If the charger is not plugged in and the battery is below 20%, it alerts you to plug in.
- If battery is somewhere around 50%, it gives a general battery update.
When Will You See Notifications?
You’ll get notifications in these situations:
- Charging and battery is full
- Charging and battery is below 80%
- Not charging and battery is low
- Not charging and battery is okay
- Not charging and battery is full
Each of these cases shows a clear pop-up message on your desktop screen.
Why Is This Useful?
There are many reasons why this battery notifier script is useful:
- Avoid overcharging your laptop battery.
- Helps maintain better battery life.
- You don’t need to keep checking the battery status manually.
- Perfect for students, professionals, and coders who often forget to monitor battery.
# Importing required libraries from plyer import notification import psutil # Get battery status battery_status = psutil.sensors_battery() is_charging = battery_status.power_plugged # Main logic if __name__ == "__main__": charge_percent = battery_status.percent if is_charging: if charge_percent <= 80: notification.notify( title = "Charging Advice", message = "To keep battery healthy, unplug after 80%.", timeout = 2 ) elif charge_percent == 100: notification.notify( title = "Battery Full", message = "Unplug now. Battery is at 100%.", timeout = 2 ) else: notification.notify( title = "Charging Status", message = "Battery charging above 80%. Consider unplugging.", timeout = 2 ) else: if charge_percent <= 20: notification.notify( title = "Low Battery Alert", message = "Battery low! Plug in your device.", timeout = 2 ) elif charge_percent <= 50: notification.notify( title = "Battery Check", message = f"Battery is at {charge_percent}%.", timeout = 2 ) elif charge_percent == 100: notification.notify( title = "Battery Full", message = "Battery is fully charged.", timeout = 2 ) else: notification.notify( title = "Battery Update", message = f"Battery level: {charge_percent}%", timeout = 2 )
Final Words
Creating a desktop battery notifier in Python is a super fun and helpful project, especially for beginners. It doesn’t need any GUI or heavy setup. Just install the libraries, write a few lines of code, and you’re good to go.
It may look small project but can add a great impression for a fresher project. For more such small and very good projects in python visit here.
Hello i think that i saw you visited my weblog so i came to Return the favore Im trying to find things to improve my web siteI suppose its ok to use some of your ideas
what is name of your blog?