ctypes - How do I set the desktop background in python? (windows) -


this i'm trying:

import ctypes import os drive = "f:\\" folder = "keith's stuff" image = "midi turmes.png" image_path = os.path.join(drive, folder, image) spi_setdeskwallpaper = 20  ctypes.windll.user32.systemparametersinfoa(spi_setdeskwallpaper, 0, image_path, 3) 

basicaly, code supposed set desktop background midi turmes.png, changes desktop, however, odd reason, it's green background (my personalized settings in windows green background behind image) how fix , make desktop this?: http://i.imgur.com/vqmzf6h.png

the following works me. i'm using windows 10 64-bit , python 3.

import os import ctypes ctypes import wintypes  drive = "c:\\" folder = "test" image = "midi turmes.png" image_path = os.path.join(drive, folder, image)  spi_setdeskwallpaper  = 0x0014 spif_updateinifile    = 0x0001 spif_sendwininichange = 0x0002  user32 = ctypes.windll('user32') systemparametersinfo = user32.systemparametersinfow systemparametersinfo.argtypes = ctypes.c_uint,ctypes.c_uint,ctypes.c_void_p,ctypes.c_uint systemparametersinfo.restype = wintypes.bool print(systemparametersinfo(spi_setdeskwallpaper, 0, image_path, spif_updateinifile | spif_sendwininichange)) 

the important part make sure use unicode string image_path if using systemparametersinfow, , byte string if using systemparametersinfoa. remember in python 3 strings default unicode.

it practice set argtypes , restype well. can "lie" , set third argtypes parameter c_wchar_p systemparametersinfow , ctypes validate passing unicode string , not byte string.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -