Why does this ctypes code not work with Python 3.3, but will work with Python 2.7?
So I am trying to make a Python 3.3 program to change the Windows desktop background using the ctypes module. I tested the following code in Python 2.7 and it worked fine. But it just won't work with Python 3.3! I am using Windows 7. Here is the code:
import ctypes
SPI_SETDESKTOPWALLPAPER=20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKTOPWALLPAPER, 0,"C:/Users/Public/Pictures/Sample Pictures/Penguins.jpg", 3)
source to share
SystemParametersInfoA
It requires 8-bit input line with ANSI encoded as a parameter, called mbcs
coded in Python ,
You will need to use SystemParametersInfoW
in python3. This is because it SystemParametersInfoW
accepts a UTF-16 string string (which is wchar_t *
in C) and the library ctypes
will automatically convert that passed unicode argument to c_wchar_p
.
For details see.
source to share