Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Control Laptop Screen Brightness Using Python?
Python can be used to control various system functions, including laptop screen brightness. The screen-brightness-control library provides simple functions to get and set screen brightness levels programmatically.
In this tutorial, we'll explore how to install and use the screen-brightness-control library to control laptop screen brightness using Python code.
Installing the Screen Brightness Control Library
First, we need to install the screen-brightness-control library using pip ?
pip install screen-brightness-control
This command will download and install the latest version of the library along with any required dependencies.
Getting Current Screen Brightness
Let's start by checking the current screen brightness level using the get_brightness() function ?
from screen_brightness_control import get_brightness
# Get the current screen brightness
current_brightness = get_brightness()
print("Current screen brightness is:", current_brightness)
The output shows the current brightness as a percentage ?
Current screen brightness is: 75
Setting Screen Brightness
The set_brightness() function allows us to adjust the screen brightness. It takes a single argument representing the desired brightness level as a percentage (0-100).
Increasing Brightness
Here's how to increase the screen brightness to 80% ?
from screen_brightness_control import set_brightness, get_brightness
# Set new brightness level to 80%
new_brightness = 80
set_brightness(new_brightness)
# Verify the change
current_brightness = get_brightness()
print("Current screen brightness is:", current_brightness)
Current screen brightness is: 80
Decreasing Brightness
Similarly, we can decrease the brightness to a lower value ?
from screen_brightness_control import set_brightness, get_brightness
# Set new brightness level to 50%
new_brightness = 50
set_brightness(new_brightness)
# Verify the change
current_brightness = get_brightness()
print("Current screen brightness is:", current_brightness)
Current screen brightness is: 50
Key Functions Summary
| Function | Purpose | Parameters |
|---|---|---|
get_brightness() |
Get current brightness level | None |
set_brightness(value) |
Set brightness to specific level | Integer (0-100) |
Practical Applications
This functionality can be useful for:
- Automated brightness adjustment based on time of day
- Battery saving by reducing brightness when power is low
- Eye strain reduction by adjusting brightness in different lighting conditions
- Accessibility features for users with visual impairments
Conclusion
The screen-brightness-control library provides a simple way to control laptop screen brightness using Python. Use get_brightness() to check current levels and set_brightness() to adjust brightness programmatically for various automation scenarios.
