1

I am using windows 8 (not yet updated to 8.1)

The code I am using is

import ctypes

SPI_SETDESKWALLPAPER = 20

ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "word.jpg", 0)

print "hi"

For some reason regardless if i give it a valid image (in the same directory as program) or not, regardless of type of image (bmp, gif, jpg) the code always ends up setting my background to a black screen.

Why is this? How can it be fixed?

Sidharth Ghoshal
  • 658
  • 9
  • 31
  • Some of the common problems you're hitting (absolute path, SPIF_*) are covered with an example solution here: http://stackoverflow.com/questions/16943733/change-windows-background-from-python/30697233#30697233 – Dan O'Boyle Jun 07 '15 at 20:41

2 Answers2

2

Try passing SPIF_SENDCHANGE (which is 2) as the last parameter. You might also need to bitwise-or it with SPIF_UPDATEINIFILE (which is 1).

ooga
  • 15,423
  • 2
  • 20
  • 21
  • It doesn't normalize the path when persisting to the user profile with `SPIF_UPDATEINIFILE`. However, loading the image uses [`SearchPath`](http://msdn.microsoft.com/en-us/library/aa365527), which searches the system `%PATH%` and the current directory. So if you use an absolute path or store the file in a `%PATH%` directory, you shouldn't get a black screen. – Eryk Sun Feb 12 '14 at 06:04
0

Sorry, I know this is late, but the problem is that you need to include the path. Instead of "image.jpg" do r"C:\path to file\image.jpg" Otherwise python doesn't know where to look for the image.