0

I'm trying to change my background image using python but I doesn't work and I can't find why.

here is my code:

import ctypes
import os

folder = "C:\\Users\\Nuriddin\\Desktop\\images"
image = "images[0].jpg"
image_path = os.path.join(folder, image)
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image_path, 0)

What is wrong in this code ? (I am sure that I entered the good path)

I am using Windows 10 and Python 3.4-x

Horai Nuri
  • 5,358
  • 16
  • 75
  • 127

2 Answers2

1

If you're calling SystemParametersInfoA, that's the ASCII/byte/char oriented interface; image_path should probably be encoded to bytes (or you should use SystemParametersInfoW for the Unicode/wchar interface).

In Python 3, str is a text type that corresponds (in ctypes) to the Unicode/wchar interfaces; bytes is a binary data type that corresponds to ASCII/char interfaces.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
0

here is the right parameter , how that its gonna help you :

SPI_SETDESKWALLPAPER = 0x14
SPIF_UPDATEINIFILE   = 0x1

lpszImage = path.join(path.dirname(path.realpath(__file__)), 'your_image.jpg')

SystemParametersInfo = windll.user32.SystemParametersInfoA

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, lpszImage, SPIF_UPDATEINIFILE)

thanks, regards .