[英]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.