Search code examples
pythoncolorsclickpyautogui

PyAutoGUI how to define color range


How do define a color range in PyAutoGUI? My code looks like this

for i in range(loop):
        if (pyautogui.pixelMatchesColor(782, 435, (110, 78, 59))):
            continue
        elif (pyautogui.pixelMatchesColor(782, 435, (color range here))):
            continue
        else:
            pyautogui.click(x=782, y=435)

I want it to click if 110, 78, 59 is false and the color range is false


Solution

  • You can use the tolerance argument.

    for i in range(loop):
        if not (pyautogui.pixelMatchesColor(782, 435, (110, 78, 59), tolerance = 10)):
            pyautogui.click(x=782, y=435)
    

    The tolerance argument specifies, how much the rgb-values of the color are allowed to vary from the rgb-values passed into the function.