简体   繁体   English

我正在尝试制作一个更新壁纸的脚本。 它给我的 OSError

[英]I am trying to make a script which updates wallpapers. It is giving my OSError

This is a snippet from my code:这是我的代码片段:

def set_background(image):
    ctypes.windll.user32.SystemParametersInfoW(20, 0, image , 0)

def set_wall(message):
    img = Image.new('RGB', auto.size(), color = (66, 70, 82))
    fnt = ImageFont.truetype('C:\\Windows\\Fonts\\consolab.ttf', 40)
    d = ImageDraw.Draw(img)
    d.text((250, 330), message, font=fnt, fill=(171, 220, 255))
    wall_path = 'E:\\pranil\\python\\jee_wallpaper.png'
    img.save(wall_path)
    set_background(wall_path)

while True:
    if datetime.today().second == 0:
        message = calculate_rem_time()  
        set_wall(message)

The error I am getting is:我得到的错误是:

OSError: [Errno 22] Invalid argument: 'E:\pranil\python\jee_wallpaper.png' OSError: [Errno 22] 无效参数: 'E:\pranil\python\jee_wallpaper.png'

How to solve this error?如何解决这个错误?

EDIT: I solved the problem..I just added time.sleep(1) between img.save(wall_path) and set_background(wall_path)编辑:我解决了问题..我只是在 img.save(wall_path) 和 set_background(wall_path) 之间添加了 time.sleep(1)

Change the wall_path to将 wall_path 更改为

wall_path = 'E:\pranil\python\jee_wallpaper.png' wall_path = 'E:\pranil\python\jee_wallpaper.png'

OSErrors are usually caused by system related errors (eg. file not found, disk full, etc.). OSErrors 通常是由系统相关错误引起的(例如,找不到文件、磁盘已满等)。 In your case your file paths look wrong.在您的情况下,您的文件路径看起来不对。 Try copying and pasting the file paths of the image files by right clicking the file and then select properties.尝试通过右键单击文件和 select 属性来复制和粘贴图像文件的文件路径。 Copy and paste the file path listed in Location: C:....复制并粘贴位置中列出的文件路径:C:....

https://docs.python.org/3/library/exceptions.html https://docs.python.org/3/library/exceptions.html

https://learn.microsoft.com/en-us/do.net/standard/io/file-path-formats https://learn.microsoft.com/en-us/do.net/standard/io/file-path-formats

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试对 python 中的更新进行 SQL 查询,但它给出了错误 - I am trying to make a SQL query of Update in python but it is giving error 我正在尝试迁移我的模型 - 但它给了我错误 - - I am trying to migrate my model - but it's giving me error - 我的代码给出了我无法理解的错误 - My code is giving an error which I am not able to understand 我正在尝试使用 playpus 为我的测试第一个 python 脚本制作 a.app - I am trying to make a .app for my test first python script using playpus 为什么会出现OSError:[Errno 2]试图生成公钥? - Why am I getting an OSError: [Errno 2] trying to generate a public key? 我正在尝试制作 django 应用程序,但此脚本错误不断出现 - I am trying to make django app but this script error keeps coming 我正在尝试在 while 循环中创建一个列表,但我的循环不会重新启动 - I am trying to make a list in a while loop but my loop will not restart 我正在尝试为我的主菜单制作两个按钮 - I am trying to make two buttons for my main menu 我正在尝试监视一个网站,但响应状态代码更新时我的代码没有更新 - I am trying to monitor a website but my code doesn't update when the response status code updates 我正在尝试在 django 中创建自定义用户模型,但它给了我很多错误 - I am trying to make a custom user model in django, but its giving me a lot of errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM