A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/how-to-control-laptop-screen-brightness-using-python/ below:

How to Control Laptop Screen Brightness using Python?

How to Control Laptop Screen Brightness using Python?

Last Updated : 17 Aug, 2021

To control the brightness of the screen we are using the screen-brightness-control library. The screen-brightness-control library has only one class and few functions. The most useful functions are mentioned below:

  1. get_brightness()
  2. set_brightness()
  3. fade_brightness()
  4. list_monitors()

Installation: We can install the package by running the following 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(display=None, method=None, verbose_error=False)

Parameters:

Returns: Current brightness level

Python3
# importing the module
import screen_brightness_control as sbc

# get current brightness  value
current_brightness = sbc.get_brightness()
print(current_brightness)

# get the brightness of the primary display
primary_brightness = sbc.get_brightness(display=0)
print(primary_brightness)

Output: Suppose the brightness was this:

Then the output will be: 

50
50

The output can be a list or an integer depending on the number of detected monitors.
 

Example 2: How to Set Screen Brightness

The set_brightness() method changes the brightness of the screen.

Syntax: set_brightness(value, display=None, method=None, force=False, verbose_error=False, no_return=False)

Parameters:

Python3
# importing the module
import screen_brightness_control as sbc

# get current brightness value
print(sbc.get_brightness())

#set brightness to 50%
sbc.set_brightness(50)

print(sbc.get_brightness())

#set the brightness of the primary display to 75%
sbc.set_brightness(75, display=0)

print(sbc.get_brightness())

 
   Output:

100
50
75

The output can be a list or an integer depending on the number of detected monitors.
 

  Example 3: How to Fade the Brightness

The fade_brightness() method gently fades the brightness to a value.

Syntax: fade_brightness(finish, start=None, interval=0.01, increment=1, blocking=True)

Parameters:

Python3
# importing the module
import screen_brightness_control as sbc

# get current brightness value
print(sbc.get_brightness())

# fade brightness from the current brightness to 50%
sbc.fade_brightness(50)
print(sbc.get_brightness())

# fade the brightness from 25% to 75%
sbc.fade_brightness(75, start = 25)
print(sbc.get_brightness())

# fade the brightness from the current
# value to 100% in steps of 10%
sbc.fade_brightness(100, increment = 10)
print(sbc.get_brightness())

 
Output:

75
50
75
100

 Example 4: How to list available monitors

The list_monitors() method returns a list the names of all detected monitors

Syntax: list_monitors(method=None)

Parameters:

Python3
# import the library
import screen_brightness_control as sbc

# get the monitor names
monitors = sbc.list_monitors()
print(monitors)

# now use this to adjust specific screens by name
sbc.set_brightness(25, display=monitors[0])

Output:

["BenQ GL2450H", "Dell U2211H"]

The names and quantity of monitors will vary depending on what is plugged into your computer.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4