To control the brightness of the screen we e are using the screen-brightness-control library. The screen-brightness-control library has only one class and three functions. The function are mention below:
Installation: We can install the package by running the follwing pip command:
pip install screen-brightness-control
Example 1: How to Get Screen Brightness
The get_brightness() method returns the current brightness level.
Syntax: get_brightness(max_value=False, raw_value=False, verbose_error=False
- max_value -: returns the maximum value the brightness can be set to. Always returns 100 on Windows. On Linux it returns the value stored in /sys/class/backlight/*/max_brightness if combined with raw_value=True
- raw_value (Linux only) -: returns the value stored in /sys/class/backlight/*/brightness
- verbose_error -: a boolean value to control how much detail any error messages should contain
Returns: Current brightness level
Output: Suppose the brightness was this:
Then the output will be:
Example 2: How to Set Screen Brightness
The set_brightness() method changes the brightness of the screen.
Syntax: set_brightness(brightness_level, force=False, raw_value=False, verbose_error=False)
- brightness_level: the level to set the brightness to. Can either be an integer or a string.
- force (Linux only): If set to False then the brightness is never set to less than 1 because on Linux this often turns the screen off. If set to True then it will bypass this check
- raw_value (Linux only): If set to ‘True’ then it attempts to write brightness_level directly to /sys/class/backlight/*/brightness. This will usually fail due to file permissions but it’s here if you need it.
- verbose_error: A boolean value to control how much detail any error messages should contain
Example 3: How to Fade the Brightness
The fade_brightness() method fades the brightness from start to finish in steps of increment, pausing for interval seconds between each step.
Syntax: fade_brightness(finish, start=None, interval=0.01, increment=1, blocking=True)
- finish: The brightness value to fade to
- start: The value to start from. If not specified it defaults to the current brightness
- interval: The time interval between each step in brightness
- increment: The amount to change the brightness by each step
- blocking: If set to False it fades the brightness in a new thread
75 50 75 100
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.