Psutil is is a cross-platform library for retrieving information on running processes and system utilization, in todays post we will be using this library to retrieve our machines battery percentage. Using plyer we will then push this as an on screen notification.
We start by retrieving the current percentage of our machines battery.
import psutil
battery = psutil.sensors_battery()
percent = battery.percent
We then move on to pushing this out as a notification. Our notification in this example has 5 characteristics which are a title, a message, an application icon, a timeout until it disappears and finally we have set it set to a toast notification.
from plyer import notification
notification.notify(title='Battery Level at ' + str(percent) + '%',
message='Its time to plug in that charger!',
app_icon = r'Image.ico',
timeout=20,
toast=True)
The full source code for this project can be found below:
import psutil
from plyer import notification
battery = psutil.sensors_battery()
percent = battery.percent
notification.notify(title='Battery Level at ' + str(percent) + '%',
message='Its time to plug in that charger!',
app_icon = r'Image.ico',
timeout=20,
toast=True)