How to get battery percentage with python? [duplic

2019-02-26 01:08发布

This question already has an answer here:

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

1条回答
闹够了就滚
2楼-- · 2019-02-26 01:31

Try this:

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

Library link is here. And check out this

查看更多
登录 后发表回答