How to get battery percentage with python? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-19 03:45:37

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/45626937/how-to-get-battery-percentage-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!