# Screen Dimmer with Python

Sometimes you just want your screens to go dark. Maybe you need a quick distraction blocker, maybe you’re stepping away from your desk, or maybe you just want to black out everything without turning monitors off. With Python, there are two quick ways to do this:

---

## Method 1: Blackout Overlay (Blocks Interaction)

This approach creates a full black overlay on every connected monitor. Windows underneath aren’t clickable, and pressing **Escape** (or closing one window) exits the blackout.

```bash
import pyglet
from screeninfo import get_monitors

# Keep track of all overlay windows
windows = []

def close_all_windows():
    for window in windows:
        window.close()

# Create fullscreen black windows on all monitors
for monitor in get_monitors():
    screen_index = get_monitors().index(monitor)
    screen = pyglet.canvas.Display().get_screens()[screen_index]
    window = pyglet.window.Window(fullscreen=True, screen=screen)

    # Black background
    pyglet.gl.glClearColor(0, 0, 0, 1)

    # Escape key exits
    @window.event
    def on_key_press(symbol, modifiers):
        if symbol == pyglet.window.key.ESCAPE or symbol == pyglet.window.key.ENTER:
            close_all_windows()

    windows.append(window)

# Run the blackout
pyglet.app.run()
```

* Covers all monitors.
    
* Blocks mouse clicks.
    
* Exit with **Esc** or **Enter**.
    

---

## Method 2: Adjust Actual Brightness

If you’d rather dim the monitors without blacking them out completely, you can use the `screen_brightness_control` library to directly change brightness levels.

```bash
import screen_brightness_control as sbc

# Set brightness to 25%
sbc.set_brightness(25)
```

Values go from `0` (minimum) to `100` (maximum). For example:

* `sbc.set_brightness(0)` → Dim to minimum.
    
* `sbc.set_brightness(50)` → Half brightness.
    
* `sbc.set_brightness(100)` → Full brightness.
    

This one doesn’t block interaction—it simply adjusts the monitor backlight.

---

## When to Use Each

* **Overlay blackout**: Instant lockout, no clicks or distractions.
    
* **Brightness control**: Subtle dimming, useful for eye strain or nighttime use.
    

Both are quick, scriptable, and more flexible than fiddling with monitor buttons.
