📅  最后修改于: 2023-12-03 15:08:25.884000             🧑  作者: Mango
在Python中设置屏幕亮度,需要使用到wmi
模块。(要求Windows 系统)
在Python中安装wmi模块,可通过pip命令进行:
pip install wmi
以下代码可以设置屏幕亮度为50(范围0~100):
import wmi
brightness = 50 # 设置屏幕亮度为50(范围0~100)
c = wmi.WMI(namespace='wmi')
methods = c.WmiMonitorBrightnessMethods()[0]
methods.WmiSetBrightness(brightness, 0) # 设置屏幕亮度
代码解释:
c = wmi.WMI(namespace='wmi')
:创建wmi的实例methods = c.WmiMonitorBrightnessMethods()[0]
:获取屏幕亮度对象methods.WmiSetBrightness(brightness, 0)
:设置屏幕亮度以下代码可以获取当前屏幕亮度:
import wmi
c = wmi.WMI(namespace='wmi')
brightness = c.WmiMonitorBrightness()[0].CurrentBrightness # 获取当前屏幕亮度
print '屏幕亮度为:', brightness # 输出
代码解释:
c = wmi.WMI(namespace='wmi')
:创建wmi的实例brightness = c.WmiMonitorBrightness()[0].CurrentBrightness
:获取当前屏幕亮度值print '屏幕亮度为:', brightness
:输出屏幕亮度值使用Python设置屏幕亮度就是这么简单!