是数组还是字符串

是数组还是字符串

本文介绍了RGB是从ImageGrab获取的吗.grab().load()是数组还是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python制作机器人.我想将一个特定像素的颜色与(83,83,83)的另一种颜色进行比较.

I am making a bot in python. I want to compare the colors of a particular pixel with another color which is (83, 83, 83).

我尝试与带有单引号和双引号的字符串进行比较.它没有用,所以我认为它可能是一个数组.

I tried comparing with a string with single and double quotes. It didn't work so I thought that it could be an array.

这是我的机器人代码

import pyautogui as py
from PIL import ImageGrab


def pressspace():
    py.keyDown('space')
    py.keyUp('space')

def jump():
    px=ImageGrab.grab().load()
    color=px[207,445]

    if color=='(83, 83, 83)':




        pressspace()

while True:
    jump()

它只是没有用,也没有按空格.我也导入了所有依赖项.请帮助,并告诉它它是一个数组,如果是,那么不如不进行比较.(注意:休息时间颜色是(247,247,247))

It just didn't work and didn't press the space. I have imported all dependencies also. Please Help and tell that is it an array and if yes, than how to compare.(Note: rest time the color is (247, 247, 247))

推荐答案

请记住,您并未说明pressspace()中的"py"是什么,也不针对您的代码段进行了说明.

Keep in mind you didn't state what 'py' in pressspace() is and does for your code snippet.

import sys, time
from PIL import ImageGrab


def pressspace():
    py.keyDown('space')
    py.keyUp('space')

def jump():
    px=ImageGrab.grab().load()
    color=px[207,445]
    c1, c2, c3 = color     # just a thought: if included you can compare and print each
                           # of them to see if they fit a certain value of your liking.

    if color==(83, 83, 83):
        print ('1 - type: ', type(color))
    else:
        print ('2 - type: ', type(color))

    print (color)  # just to print always the color

    time.sleep(1)   # pause it for one second to prevent SPAM in the output.

    # pressspace()

while True:
    jump()
    sys.stdout.flush()  # forces to print directly the result from within an editor if used.

在我的情况下,它是<class 'tuple'>

这篇关于RGB是从ImageGrab获取的吗.grab().load()是数组还是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 07:00