[英]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)
Exact output:确切的 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
It is working all fine if I put TradeFrom and TradeTo outside of while loop, can anyone explain why it breaks down after I put it inside while loop?如果我将 TradeFrom 和 TradeTo 放在 while 循环之外,一切正常,谁能解释为什么我把它放在 while 循环中后它会崩溃?
I think you need to fix the logic.我认为您需要修复逻辑。 Right now you're looking for two objects on the screen.
现在,您正在屏幕上寻找两个对象。 Your statement is saying that if the first object is not found but the second one is, then assign coordinates from the first object...which is None and that's why your code is failing.
您的声明是说,如果未找到第一个 object 但第二个是,则从第一个 object 分配坐标...这是 None ,这就是您的代码失败的原因。 Not sure what the intended outcome is, but maybe try this:
不确定预期的结果是什么,但也许试试这个:
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)
Also, I suggest you code in a break key so it's easy to interrupt this loop另外,我建议你在 break 键中编写代码,这样很容易中断这个循环
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.