为什么我可以使用ImageGrab.grab(300,200,400,150)
而不是这个:ImageGrab.grab(bbox)
代码和错误消息:
def wl(wx,wy):
local = win32gui.GetWindowRect(wds)
dx = wx+local[0]
dy = wy+local[1]
return (dx,dy)
def wlw (x,y,z,a):
return wl(x,y)+wl(z,a)
bbox = wlw(300,200,400,150)
pic = ImageGrab.grab(bbox)
pic.save(r'C:\Users\shang\Desktop\test.jpg')
Traceback (most recent call last):
File "C:/Users/shang/PycharmProjects/test/First.py", line 90, in <module>
pic.save(r'C:\Users\shang\Desktop\test.jpg')
File "C:\Users\shang\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2088, in save
save_handler(self, fp, filename)
File "C:\Users\shang\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\JpegImagePlugin.py", line 779, in _save
ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize)
File "C:\Users\shang\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\ImageFile.py", line 525, in _save
e.setimage(im.im, b)
SystemError: tile cannot extend outside image
Process finished with exit code 1
我无法运行该程序,因为我没有不想安装的
wds
或win32gui
。请注意,bbox是一个具有4个值的元组,而ImageGrab.grab具有4个参数,因此请尝试ImageGrab.grab(*bbox)
,其中元组扩展为4个变量。所以:一些建议。试着遵循PEP8的指导方针,使用空格和白线来提高代码的可读性(比如逗号后面的空格和函数之间的两行)。 使名称更具描述性,什么是函数
wl
和wlw
?什么是local
,z
,a
?当一个函数描述这些函数是什么样子的get_local_window
或者类似的东西时。 是否真的有必要使用两个函数wl
和wlw
,难道wl
不只是wlw
的一部分吗相关问题 更多 >
编程相关推荐