【Python】监控笔记本电池状态

pip install psutil

if __name__ == '__main__':
    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)

 

posted @ 2022-10-25 22:17  淡怀  阅读(101)  评论(0编辑  收藏  举报