图片不会保存 Python pyautogui
Image won't save Python pyautogui
我正在尝试在 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'
稍微编辑一下代码,它对我来说非常有效。
试试这个:
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")
我正在尝试在 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'
稍微编辑一下代码,它对我来说非常有效。
试试这个:
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")