简体   繁体   English

PyAutoGui TypeError:无法解压不可迭代的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)

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.

相关问题 Pyautogui Image 工作一段时间后不可迭代,TypeError: cannot unpack non-iterable NoneType object - Pyautogui Image non-iterable after working for a while, TypeError: cannot unpack non-iterable NoneType object Pyautogui - 单击图像:无法解压不可迭代的 NoneType 对象 - Pyautogui - click on image: cannot unpack non-iterable NoneType object "有人可以向我解释为什么 pyautogui TypeError: cannot unpack non-iterable NoneType object" - Can someone explain to me why pyautogui TypeError: cannot unpack non-iterable NoneType object Python pyautogui bot 工作一段时间后出现TypeError: cannot unpack non-iterable NoneType object 解决方法 - Python pyautogui bot works for some time and then TypeError: cannot unpack non-iterable NoneType object Solution Numpy 抛出 TypeError: cannot unpack non-iterable NoneType object - Numpy throwing TypeError: cannot unpack non-iterable NoneType object 方法 Euler TypeError: cannot unpack non-iterable NoneType object - Method Euler TypeError: cannot unpack non-iterable NoneType object -- TypeError: cannot unpack non-iterable NoneType object - -- TypeError: cannot unpack non-iterable NoneType object TypeError:无法解压不可迭代的 NoneType 对象 - TypeError: cannot unpack non-iterable NoneType object TypeError:无法解压不可迭代的 NoneType 对象错误 - TypeError: cannot unpack non-iterable NoneType object Error 类型错误:无法解压不可迭代的 object - TypeError: cannot unpack non-iterable object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM