DeaD_EyE icon

minimal intel_backlight

DeaD_EyE | PRO | 03/28/23 09:02:05 AM UTC | 0 ⭐ | 1296 👁️ | Never ⏰ | []
Python |

680 B

|

None

|

0 👍

/

0 👎

from pathlib import Path
from tkinter import Button, Tk
from tkinter.ttk import Scale
 
BASE = Path("/sys/class/backlight/intel_backlight")
BRIGHTNESS = BASE / "brightness"
MAX_BRIGHTNESS = int(BASE.joinpath("max_brightness").read_text())
 
 
def set(percent: float):
    value = MAX_BRIGHTNESS / 100 * float(percent)
    BRIGHTNESS.write_text(str(int(value)))
 
 
def get() -> float:
    return int(BRIGHTNESS.read_text()) / MAX_BRIGHTNESS * 100
 
 
def gui() -> Tk:
    root = Tk()
    Scale(root, value=get(), from_=0, to=100, command=set).pack()
    Button(root, text="Close", command=root.destroy).pack()
    return root
 
 
if __name__ == "__main__":
    gui().mainloop()

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎