简体   繁体   English

如何使用 Python 导航 Windows 10 UI 以更改特定设置?

[英]How can I use Python to navigate Windows 10 UI to change a specific setting?

What I want to do is create a script that allows me to toggle Windows 10 clear and dark mode without having to manually go to settings every time, which requires 4 or 5 steps.我想要做的是创建一个脚本,允许我切换 Windows 10 清晰和黑暗模式,而无需每次手动 go 设置,这需要 4 或 5 个步骤。

I've been looking at the os module but haven't found a method that would let me navigate the task bar or the notifications center to access the settings from there, nor have I found a way to change that setting from a folder using basic Windows Explorer navigation.我一直在查看os模块,但没有找到一种方法可以让我导航任务栏或通知中心以从那里访问设置,也没有找到一种方法来使用基本的文件夹更改该设置Windows 资源管理器导航。

The process would be to open the settings, navigate to the colors setting and toggle the color.该过程是打开设置,导航到 colors 设置并切换颜色。 Or do it by altering some file on the Windows folder for example, that would change that setting without opening the settings window.或者通过更改 Windows 文件夹中的某些文件来做到这一点,例如,这将在不打开设置 window 的情况下更改该设置。

I don't think there is a python library that can tweak Windows UI settings (eg: colors, mode, ..).我认为没有可以调整 Windows UI 设置的 python 库(例如:colors,模式,..)。 However, to enable the dark mode in your Windows 10, you can use the python built-in modulesubprocess to execute a registry command and set the value of the keys AppsUseLightTheme and SystemUsesLightTheme to 0 .但是,要在 Windows 10 中启用暗模式,您可以使用 python 内置模块subprocess进程执行注册表命令并将键AppsUseLightThemeSystemUsesLightTheme的值设置为0

在此处输入图像描述

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize]
    "AppsUseLightTheme"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize]
    "SystemUsesLightTheme"=dword:00000000

With Python, try this:使用 Python,试试这个:

import subprocess

dark_app_mode = ['reg.exe', 'add', 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize', 
           '/v', 'AppsUseLightTheme', '/t', 'REG_DWORD', '/d', '0', '/f']
dark_windows_mode = ['reg.exe', 'add', 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize', 
           '/v', 'SystemUsesLightTheme', '/t', 'REG_DWORD', '/d', '0', '/f']

subprocess.run(dark_app_mode)
subprocess.run(dark_windows_mode)

Or this:或这个:

from subprocess import Popen

dark_app_mode = 'reg.exe add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 0 /f'
dark_windows_mode = 'reg.exe add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v SystemUsesLightTheme /t REG_DWORD /d 0 /f'

commands = [dark_app_mode, dark_windows_mode]

processes = [Popen(cmd, shell=True) for cmd in commands]

RESULT:结果:

This will set a FULL dark mode in your Windows 10 (or 11):这将在 Windows 10(或 11)中设置全暗模式:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM