【问题标题】:Python Background change with Python 3 not working [duplicate]Python 3的Python背景更改不起作用[重复]
【发布时间】:2015-12-21 18:01:08
【问题描述】:

我正在尝试使用 python 更改我的背景图像,但我不起作用,我找不到原因。

这是我的代码:

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)

这段代码有什么问题? (我确定我走的是好路)

我使用的是 Windows 10 和 Python 3.4-x

【问题讨论】:

  • @baldr 谢谢没想到来自Python的版本。

标签: python python-3.x


【解决方案1】:

如果你调用SystemParametersInfoA,那是面向ASCII/字节/字符的接口; image_path 可能应该被编码为 bytes(或者你应该使用 SystemParametersInfoW 作为 Unicode/wchar 接口)。

在 Python 3 中,str 是一种文本类型,对应于(在 ctypes 中)Unicode/wchar 接口; bytes是二进制数据类型,对应ASCII/char接口。

【讨论】:

    【解决方案2】:

    这是正确的参数,它将如何帮助您:

    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)
    

    谢谢, 问候。

    【讨论】:

      猜你喜欢
      • 2016-10-28
      • 2019-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多