Skip to main content
Key2Goal

Main navigation

  • Home
  • About Us
  • Contact us
  • Glossary
  • Privacy Policy
User account menu
  • Log in

Breadcrumb

  1. Home

Python Script to check battery status Windows 11

Below an example of a Python script that checks the battery status on a Windows system:

import psutil

battery = psutil.sensors_battery()
plugged = battery.power_plugged
percent = battery.percent

if plugged:
    status = "Plugged In"
else:
    status = "Unplugged"

print(f"Battery Status: {status}")
print(f"Battery Percentage: {percent}%")

This script uses the psutil library, which provides system-related information, including battery status. You can install it using pip by running pip install psutil.

The psutil.sensors_battery() function retrieves the battery information, and battery.power_plugged indicates whether the system is plugged in or not. The battery.percent attribute gives the current battery percentage.

The script then checks the plugged variable to determine the battery status (plugged in or unplugged) and prints the status and battery percentage.

You can run this script on a Windows system with Python installed to get the battery status information.

  • Log in to post comments

Comments

Article category

  • Drupal
  • Wordpress
  • Java
  • Javascipt
  • HTML
  • CSS
  • IOS
  • Android
  • PHP
  • MySQL
  • Other
  • Command line
  • NodeJs
  • Drupal 8
  • Drupal 7
  • GIT
  • DevOps
  • Python
  • Xampp
  • Server
  • Artificial intelligence
  • AppScript
  • Windows

Recent content

  • ERROR: Cannot create symbolic link : A required privilege is not held by the client.
    3 hours 52 minutes ago
  • Differences Between Bootstrap 3 & Bootstrap 4
    1 month ago
  • About Us
    1 month ago
  • Privacy Policy
    1 month ago
  • Create a Virtual Host on Xampp in 5 steps
    3 months ago
  • How to setup Multisite in drupal 9
    9 months ago
  • How to creating a FOR loop and a WHILE loop in JavaScript
    9 months ago
  • Calculator program HTML & PHP
    9 months ago
  • Algothrim to create a web application
    9 months ago
  • 10 Git Useful Commands for Every Developer
    9 months ago
© Copyright 2017 - 2026 key2Goal. All Rights Reserved