zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

Python监控状态 笔记本 电池
2023-09-11 14:16:50 时间

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)