如何使用 python 获取电池百分比?

How to get battery percentage with python?

如何使用 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)

图书馆 link 是 here. And check out this