2017-05-04 3 views
0
#! python3 
import pyautogui 
import time 
pyautogui.screenshot('first.png') #take a SS of my entire screen 
check = pyautogui.locateCenterOnScreen('first.png') # set the value of check to center of screen assuming it will be the same as the SS...it will 
print(check) #(960, 540) is the center of my screen and is stored in check 
while True: #inf loop 
    pyautogui.screenshot('Test.png') #take a second Screenshot 
    idleout = pyautogui.locateCenterOnScreen('Test.png') #set the value of idleout with the center of test.jpg 
    print(idleout) #(960, 540) is the center suprised?? 
if idleout != check: #idleout != (960, 540) then this should happen 
    pyautogui.press('space') #space is never pressed or any action taken ive even tried with print("hello") 

내가 원하는 것은 화면이 현재 내 화면에있는 것과 일치하지 않으면 어떤 조치를 취할 것입니다. 메신저는 여기pyautogui if 명령문이 실행되지 않는 Python 자동화

답변

0

연기에서 실행 잘 모르겠어요 만약 당신이 당신의 while True 루프의 외부 if 문을 가지고있는 것처럼 SO (귀하의 의견이 키워드로 표시되는) 올바르게 설정되어 있지만, 보이는됩니다에 서식. 그렇다면 결코 실행되지 않을 것입니다.

#! python3 
import pyautogui 
import time 
pyautogui.screenshot('first.png') 
check = pyautogui.locateCenterOnScreen('first.png') 
print(check) 
while True: 
    pyautogui.screenshot('Test.png') 
    idleout = pyautogui.locateCenterOnScreen('Test.png') 
    print(idleout) 
    if idleout != check: 
     pyautogui.press('space') 
+1

그래서 모두 지워야합니다. 들여 쓰기가 빠졌지 만 구문이 정확했기 때문에 오류가 표시되지 않았습니다. 감사! – John

+0

그게 다행 인 것을 기쁘게 생각합니다! – AetherUnbound

관련 문제