Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get battery percentage with python? [duplicate]

How to get battery percentage with python?
Maybe some win32api functions may help.

like image 214
Black Thunder Avatar asked Aug 11 '17 04:08

Black Thunder


People also ask

How do I show the percentage of battery on my Iphone?

Just swipe down from the top-right corner of your display. With iOS 16, you can turn on the battery percentage so it appears in your status bar. Go to Settings > Battery, and turn on Battery Percentage.


1 Answers

Try this:

import psutil
battery = psutil.sensors_battery()
plugged = battery.power_plugged
percent = str(battery.percent)
plugged = "Plugged In" if plugged else "Not Plugged In"
print(percent+'% | '+plugged)

Library link is here. And check out this

like image 106
whackamadoodle3000 Avatar answered Sep 20 '22 17:09

whackamadoodle3000