Home > other >  Python - How to change windows color theme
Python - How to change windows color theme

Time:01-13

My goal is to make a script to apply a certain boundle of settings all at once to my computer if something specific happens. I am currently stuck, at how to change the windows color theme. I could figure out, how to change the theme from light to dark and reverse using this code:

import subprocess

command = ['reg.exe', 'add', 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize', 
           '/v', 'AppsUseLightTheme', '/t', 'REG_DWORD', '/d', '0', '/f']
subprocess.run(command)

This code works, and i can use it to change from light to dark theme. But there are also other settings in this settingsboundle:

The settings

i want to be able to change color accent, like in this image there is blue selected, to another color (for example red). I could not find any way to do this, nor how to universally change windows settings.

Do you know any way of changing the windows color accent using python?

Do you know of any way to change any windows setting, (such as the background, mouse cursor size, font, font size), perhaps is there even a module to it which can be used like in the following example:

import example

setting2 = windows.CURSOR_SIZE
setting2v = 15

example.change.setting(setting2, setting2v)
print("succesfully changed setting "   str(setting2)   " to value "   str(setting2v))

thank you :)

(I am very sorry for bad english, i am still learning it)

CodePudding user response:

You are looking for running powershell commands using python.

First, find out the needed command, there is probably a command for every action you want in windows.

Then, you can do it as follows:

import subprocess

hideBar = "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"
def run(cmd):
    subprocess.run(["powershell", "-Command", cmd])

run(hideBar)

Good luck with your script!

Reference: How to change a certain windows setting using python?

CodePudding user response:

There's no Python module that makes it that easy to tweak Windows UI settings programmatically. But you already have a working example of using reg.exe from Python. You can use your working example as a basis for modifying other registry settings. Now it's just a matter of locating the appropriate registry keys for the settings you want to change. You can do this using Google, example search query: registry key for personalize accent color.

Here's a StackExchange post going over the keys for many Personalize settings:

https://superuser.com/a/1395560/54746

  •  Tags:  
  • Related