2017-05-04 98 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