【问题标题】:Image won't save Python pyautogui图像不会保存 Python pyautogui
【发布时间】:2021-11-02 01:29:48
【问题描述】:

我正在尝试在 Python 中截取屏幕截图并尝试保存图像,但它给了我一个错误

这是代码:

import pyautogui as pygui

def take_screenshot():
    ss = pygui.screenshot()
    cd = os.getcwd()
    ss.save(cd+"/Data/Screenshots/Screenshot.png")

这是错误代码:

  File "Main.py", line 67, in <module>
    scan_func()
  File "Main.py", line 53, in scan_func
    take_screenshot()
  File "/home/user/IXL-Bot/Data/ExternalModules/ScreenshotModules.py", line 7, in take_screenshot
    ss.save(cd+"/Data/Screenshots/Screenshot.png")
  File "/home/user/.local/lib/python3.7/site-packages/PIL/Image.py", line 2232, in save
    fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/IXL-Bot/Data/Screenshots/Screenshot.png'

【问题讨论】:

    标签: python python-3.x screenshot pyautogui


    【解决方案1】:

    稍微编辑一下代码,对我来说效果很好。

    试试这个:

    import pyautogui as pygui
    import os  #You dont seem to have included this in your example code
    
    def take_screenshot():
        ss = pygui.screenshot()
        cd = os.getcwd()
        print(cd+/Data/Screenshots/Screenshot.png) #Check if the path it 
                                                   #specifying is correct
        ss.save(cd+"/Data/Screenshots/Screenshot.png")
    

    【讨论】:

      猜你喜欢
      • 2015-08-22
      • 1970-01-01
      • 2020-11-04
      • 2016-06-11
      • 2016-03-11
      • 2016-04-11
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多