Is RGB taken from ImageGrab.grab().load() is in array or string

风流意气都作罢 提交于 2020-02-24 12:35:09

问题


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.

This is my code of the bot

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()

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))


回答1:


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.

In my case its an <class 'tuple'>



来源:https://stackoverflow.com/questions/56635871/is-rgb-taken-from-imagegrab-grab-load-is-in-array-or-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!