[英]How Would You Change Windows Wallpaper Using Python & Hardware Detection?
我是 Python 的初学者,所以任何帮助将不胜感激,
我有一台我使用的 Windows 笔记本电脑和一个连接到它的 2 台显示器,当我使用显示器时,笔记本电脑盖是关闭的,当我使用笔记本电脑时,我远离显示器
我想创建一个脚本来执行以下操作:
我想基本上把它变成代码:
Image 1 = "C:\\Users....\Image1.png"
Image 2 = "C:\\Users....\Image2.png"
Laptop Screen = HP ENVY x360 Screen?
Dual Monitors = SAMSUNG 24 and SAMSUNG 24
if Dual Monitors is connected:
set wallpaper to Image 2 on Stretch
else:
set wallpaper to Image 1 on Fill
有人可以建议我如何做到这一点,但在 Python 中?
如果您好奇,这里是脚本:
import ctypes
import subprocess
import re
# Wallpapers And Their Paths
Image1 = r"C:\Users\user\Documents\People\Farzanul Chowdhury\Python\Automatic Wallpaper\Images\1.png"
Image2 = r"C:\Users\user\Documents\People\Farzanul Chowdhury\Python\Automatic Wallpaper\Images\2.png"
# Get The Name of The Montiors Active
proc = subprocess.Popen(['powershell', 'Get-WmiObject win32_desktopmonitor;'], stdout=subprocess.PIPE)
res = proc.communicate()
monitor = re.findall('(?s)\r\nName\s+:\s(.*?)\r\n', res[0].decode("utf-8"))
AvailableMonitor = f"z{monitor}z"
# Set The Wallpaper
if AvailableMonitor == "z['Generic PnP Monitor']z":
ctypes.windll.user32.SystemParametersInfoW(20, 0 , Image1, 0)
else:
ctypes.windll.user32.SystemParametersInfoW(20, 0 , Image2, 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.