Skip to content
조회 수 5321 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

파이썬 pyautogui 자주쓰는 이미지 서치 def 지정하기


 

 
#https://goodthings4me.tistory.com/491
import pyautogui
import pywinauto
import pyperclip
import time
import cv2 #open-cv2-python
 
#---
 
#캡쳐한 이미지가 화면에 여러개 일때 n번째
#원하는 이미지의 위치들을 리스트에 저장해놓고 for문으로 하나씩 꺼내어 쓰는 개념
def m_imgs(fname):
    for i in pyautogui.locateAllOnScreen(fname):
        pyautogui.click(i, duration=0.25)
        print(i)
 
#동일한 이미지 중 n번째 이미지 클릭
def m_img(fname,cntnum):
    cnt=0
    for i in pyautogui.locateAllOnScreen(fname):
        if cnt is cntnum:
            pyautogui.click(i, duration=0.25)
            print(i)
        cnt=cnt+1

#범위 안에서만 캡처한 이미지를 찾고 싶을 때
def m_imgs(fname,x1,y1,x2,y2):
    img_capture = pyautogui.locateOnScreen(fname, region=(x1,y1,x2,y2))
    pyautogui.moveTo(img_capture)
    start = time.time()  # 시작 시간 저장
    print("코드 실행 시간 :", time.time() - start) # 현재시각 - 시작시각 = 실행 시간
 
# 동일 형상 중에 특정번째만 동작하기
def Dupclick(num,fname):
    for idx, i in enumerate(pyautogui.locateAllOnScreen(fname), start=1):
        if idx == num: # num번쨰 등장하는 형상에만 동작 *참고 : start=1
            pyautogui.click(i)
 
#검색된 이미지의 x,y좌표를 구해서 img_p 변수로 리턴합니다.
def imgif(url):
    img_p = pyautogui.locateOnScreen(url)
    print('이미지 xy좌표:',img_p)
    return img_p
 
#검색된 이미지를 클릭합니다.
def imgclick(url):
    img_xy = pyautogui.locateOnScreen(url)
    time.sleep(random.randrange(1,3))
    pyautogui.click(img_xy)
    print('이미지 클릭:',img_xy)
   
#검색된 이미지를 xy좌표를 클릭합니다.
def xyclick(url):
    img_xy = pyautogui.locateOnScreen(url)
    time.sleep(random.randrange(1,3))
    pyautogui.moveTo(img_xy)
    time.sleep(random.randrange(1,3))
    pyautogui.click()
    print('xy좌표 클릭:',img_xy)    
    pyautogui.moveTo(100, 200) # x 100, y 200 위치로 바로 이동
 
#상하좌우 범위를 지정한 파일이름으로 저장합니다.
def imgshot(fname,x1,y1,x2,y2):
    img_sc = pyautogui.screenshot(fname, region=(x1,y1,x2,y2))
    time.sleep(random.randrange(1,3))
#---
 
windows = pyautogui.getAllWindows()
 
for window in windows:
    print(window)
   
noactive = pyautogui.getWindowsWithTitle('농업교육포털 - Chrome')[0]
if noactive.isActive == False:
    noactive.activate()
   
#https://agriedu.net/page/client_study_ing#appPage_study_status_ing_online
 
# 아래방향키 9번 누른다.
 
fname="C:/Python/py_code/automouse/img/nongsa/test-0.png"
m_img(fname,1)



 

 

로그인 후 댓글쓰기가 가능합니다.

?

  1. 09
    Mar 2022
    22:45

    Visual Studio Code 파이썬 인터프리터 경로 변경하기

    Category파이썬 Views9360
    Read More
  2. 22
    Jan 2022
    08:25

    pytube 사용방법

    Category파이썬 Views4241
    Read More
  3. 02
    Jan 2022
    14:43

    엘리베이터 승강기시설안전관리법

    Category유용한상식 Views2726
    Read More
  4. 16
    Dec 2021
    06:38

    토지(농지) 양도소득세 계산방법

    Category유용한상식 Views3591
    Read More
  5. 03
    Dec 2021
    13:03

    경주시도시계획조례 - 농지

    Category유용한상식 Views2466
    Read More
  6. 26
    Nov 2021
    18:55

    하천부지 매입관련

    Category유용한상식 Views3696
    Read More
  7. 02
    Oct 2021
    10:22

    경매로 낙찰받은 아파트의 세입자가 집을 비워주지 않을때

    Views3710
    Read More
  8. 28
    Sep 2021
    13:54

    로블록스 스튜디오 파트 생성 스크립트

    Views2028
    Read More
  9. 28
    Sep 2021
    12:15

    로블록스 스튜디오 파트속성

    Category컴퓨터잡담 Views3146
    Read More
  10. 28
    Sep 2021
    10:57

    로블록스 스튜디오 imagelabel 이미지추가버튼이 안나올때 해결방법

    Views2703
    Read More
  11. 23
    Sep 2021
    22:29

    파이썬 팍스넷 추천종목 특정페이지 크롤링

    Category파이썬 Views3504
    Read More
  12. 18
    Sep 2021
    09:46

    Python 메타블로그 글쓰기(제로보드, xpressengine blog api)

    Category파이썬 Views3487
    Read More
  13. 17
    Sep 2021
    08:43

    python 에서 구글 캘린더 api 이용하기(server to server)

    Category파이썬 Views3336
    Read More
  14. 11
    Sep 2021
    14:26

    파이썬 openyxl 엑셀파일(xlsx) 저장하기

    Category파이썬 Views2664
    Read More
  15. 09
    Sep 2021
    21:56

    파이썬 오류모음(에러모음)

    Category파이썬 Views3791
    Read More
  16. 27
    Aug 2021
    17:16

    파이썬 JSON으로 받아온 데이터의 Key 값 가져오기

    Category컴퓨터잡담 Views11104
    Read More
  17. 25
    Aug 2021
    12:53

    QCY T10 한글 사용법 설명서

    Views703
    Read More
  18. 11
    Aug 2021
    17:11

    유머사이트 모음

    Category재미재미 Views2573
    Read More
  19. 10
    Aug 2021
    22:13

    파이썬 카카오톡 나에게 알림메시지 보내기

    Views3419
    Read More
  20. 30
    Jul 2021
    09:50

    파이썬 find, select 사용법

    Category컴퓨터잡담 Views1448
    Read More
Board Pagination Prev 1 2 3 4 5 ... 16 Next
/ 16

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소