2016-06-26 14 views
0

私はSOとGoogleのすべての例を試しましたが、どれも動作しませんでした。私はなぜ、スクリプトが間違いなく終了するのかわかりません。しかし、背景イメージは変化しません。私はそのイメージの絶対パスを入れました。私はjpg,pngフォーマットを試しましたが、基本的にはすべて試しましたが、すべての例はエラーなしで終了しましたが、背景イメージは変更されません。このための実例がありますか? Windows-7 Python 3.4Python 3.4のデスクトップ背景画像が変更されない

いくつかの例は機能しませんでした。次のコードを使用して

import ctypes 
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "myimage.jpg" , 0) 
######################################## 

#This example can't find images, but I put absolute path to it. Don't know what's the problem 
import struct 
import ctypes 


SPI_SETDESKWALLPAPER = 20 
WALLPAPER_PATH = 'C:\\your_file_name.jpg' 


def is_64_windows(): 
    """Find out how many bits is OS. """ 
    return struct.calcsize('P') * 8 == 64 


def get_sys_parameters_info(): 
    """Based on if this is 32bit or 64bit returns correct version of SystemParametersInfo function. """ 
    return ctypes.windll.user32.SystemParametersInfoW if is_64_windows() \ 
     else ctypes.windll.user32.SystemParametersInfoA 


def change_wallpaper(): 
    sys_parameters_info = get_sys_parameters_info() 
    r = sys_parameters_info(SPI_SETDESKWALLPAPER, 0, WALLPAPER_PATH, 3) 

    # When the SPI_SETDESKWALLPAPER flag is used, 
    # SystemParametersInfo returns TRUE 
    # unless there is an error (like when the specified file doesn't exist). 
    if not r: 
     print(ctypes.WinError()) 


change_wallpaper() 
+0

コードを表示できますか? –

+0

私が試した10の例があります。本当に? – GLHF

+0

よく、あなたは助けを得るために多くの情報を与えていません。あなたは働くべきだと思うものを選ぶことができますか? –

答えて

1

試してみてください。

import struct 
import ctypes 
import os 

def is_64_windows(): 
    """Find out how many bits is OS. """ 
    return 'PROGRAMFILES(X86)' in os.environ 

def get_sys_parameters_info(): 
    """Based on if this is 32bit or 64bit returns correct version of SystemParametersInfo function. """ 
    return ctypes.windll.user32.SystemParametersInfoW if is_64_windows() \ 
     else ctypes.windll.user32.SystemParametersInfoA 

def change_wallpaper(): 
    sys_parameters_info = get_sys_parameters_info() 
    r = sys_parameters_info(SPI_SETDESKWALLPAPER, 0, WALLPAPER_PATH, 3) 
    if not r:   # When the SPI_SETDESKWALLPAPER flag is used, SystemParametersInfo returns TRUE unless there is an error (like when the specified file doesn't exist). 
     print(ctypes.WinError()) 

SPI_SETDESKWALLPAPER = 20 
WALLPAPER_PATH = 'C:\\your_file_name.jpg' 
change_wallpaper() 

私はあなたの問題は、あなたが、あなたのis_64_windows()関数がFalse返しますが、それは実際に動作するはずですTrue'PROGRAMFILES(X86)' in os.environで、64個の窓が、32のpythonを持っているということだと思います。

+0

うわー。これは実際に動作します。多くはうわー。私は複数回アップヴォートすることができますように願っています。 – GLHF

関連する問題