import pyautogui as pag
from PIL import ImageGrab
# 캡쳐할 영역의 왼쪽 상단 모서리와 오른쪽 하단 모서리의 좌표값을 미리구해둔다.
# print(pag.position())
#위에 구한값을 변수에 담아둔다
left_top = (100, 100)
right_bottom = (300, 300)
#좌측상단의 x, 우측하단의 y값을 저장해둔다
left_top_x = left_top[0]
right_bottom_y = right_bottom[1]
#캡쳐 범위의 폭과 높이를 구한다
capture_width = right_bottom[0]-left_top[0]
capture_height = right_bottom[1]-left_top[1]
#캡쳐 경로와 이름을 지정한다
path = r"C:\capture1.png"
#스크린샷
pag.screenshot(path, region=(left_top_x, right_bottom_y, capture_width, capture_height))
##########################################################################################
#전체코드
import pyautogui as pag
from PIL import ImageGrab
# 캡쳐할 영역의 왼쪽 상단 모서리와 오른쪽 하단 모서리의 좌표값을 미리구해둔다.
# print(pag.position())
left_top = (100, 100)
right_bottom = (300, 300)
left_top_x = left_top[0]
right_bottom_y = right_bottom[1]
capture_width = right_bottom[0]-left_top[0]
capture_height = right_bottom[1]-left_top[1]
path = r"C:\capture1.png"
pag.screenshot(path, region=(left_top_x, right_bottom_y, capture_width, capture_height))
아래 이미비 비교를 활용해 더 다양한 매크로 구현이 가능하다
파이썬 매크로 pyautogui 이미지 비교후 클릭
전체화면을 캡쳐후 저장한 이미지(픽셀)이 존재하는지 탐색후 클릭하는 코드입니다. import pyautogui as pag from PIL import ImageGrab path = r"C:\1.png" path = pag.locateOnScreen(path) if(path is not Non..
tmizip.tistory.com