![](/img/trans.png)
[英]Pyautogui Image non-iterable after working for a while, TypeError: cannot unpack non-iterable NoneType object
[英]PyAutoGui TypeError: cannot unpack non-iterable NoneType object
import pyautogui
import cv2
import time
while(True):
TradeFrom = pyautogui.locateCenterOnScreen("Screenshot_256.png", grayscale= True, confidence=0.9)
TradeTo = pyautogui.locateCenterOnScreen("Screenshot_258.png", grayscale=True, confidence=0.9)
if TradeFrom == None:
if TradeTo == None:
time.sleep(30)
continue
elif TradeTo != None:
z,t=TradeFrom
pyautogui.moveTo(z,t,3)
pyautogui.rightClick()
#TODO ÇOK YAPILACAK ŞEY VAR AMK
else:
x,y = TradeTo
pyautogui.moveTo(x,y,3)
pyautogui.rightClick()
InviteToParty = pyautogui.locateCenterOnScreen("InviteToParty.png", grayscale= True, confidence=0.9)
Invite_X,Invite_Y = InviteToParty
pyautogui.moveTo(Invite_X,Invite_Y)
確切的 output:
Traceback (most recent call last):
File "C:/Users/emosc/PycharmProjects/heuheu/main.py", line 12, in <module>
z,t=TradeFrom
TypeError: cannot unpack non-iterable NoneType object
如果我將 TradeFrom 和 TradeTo 放在 while 循環之外,一切正常,誰能解釋為什么我把它放在 while 循環中后它會崩潰?
我認為您需要修復邏輯。 現在,您正在屏幕上尋找兩個對象。 您的聲明是說,如果未找到第一個 object 但第二個是,則從第一個 object 分配坐標...這是 None ,這就是您的代碼失敗的原因。 不確定預期的結果是什么,但也許試試這個:
import pyautogui
import cv2
import time
while(True):
TradeFrom = pyautogui.locateCenterOnScreen("Screenshot_256.png", grayscale= True, confidence=0.9)
TradeTo = pyautogui.locateCenterOnScreen("Screenshot_258.png", grayscale=True, confidence=0.9)
if TradeFrom == None:
if TradeTo == None:
time.sleep(30)
continue
elif TradeTo != None:
z,t=TradeTo
pyautogui.moveTo(z,t,3)
pyautogui.rightClick()
#TODO ÇOK YAPILACAK ŞEY VAR AMK
else:
x,y = TradeFrom
pyautogui.moveTo(x,y,3)
pyautogui.rightClick()
InviteToParty = pyautogui.locateCenterOnScreen("InviteToParty.png", grayscale= True, confidence=0.9)
Invite_X,Invite_Y = InviteToParty
pyautogui.moveTo(Invite_X,Invite_Y)
另外,我建議你在 break 鍵中編寫代碼,這樣很容易中斷這個循環
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.