17

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

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Nouman
  • 6,947
  • 7
  • 32
  • 60

1 Answers1

36

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

whackamadoodle3000
  • 6,684
  • 4
  • 27
  • 44