2017-05-04 54 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") 

我想要发生的是如果屏幕截图不匹配什么是我的屏幕上它会做一些行动。 IM在运行油烟这里Python自动化与pyautogui如果语句不会执行

回答

0

我不知道,如果在SO设置正确(你的意见是显示关键字),但它看起来你有你的while True环外的if语句格式。如果是这种情况,它将永远不会被执行(或检查)。

#! 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