This question already has answers here:
Getting Battery Capacity in Windows with Python

(5个答案)


3年前关闭。




如何使用python获取电池电量百分比?
也许某些 win32api 函数可能会有所帮助。

最佳答案

试试这个:

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)
库链接为here。并检查this

关于python - 如何使用python获取电池电量百分比?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45626937/

10-12 17:48