Search code examples
pythonimageautopy

Why does this line of code produce the TypeError: 'tuple' object cannot be interpreted as an integer


I'm trying to print the color value of a screenshot for some monitoring software. For this I'm using autopy, which has the following command on their website for extracting an rgb value of a pixel.

autopy.color.hex_to_rgb(autopy.screen.get_color(100, 100))

I don't know much about Python or autopy, so any help is appreciated

Edit: Here's the full error message:

Traceback (most recent call last): File "Scr.py", line 12, in autopy.color.hex_to_rgb(autopy.screen.get_color(100, 100)); TypeError: 'tuple' object cannot be interpreted as an integer


Solution

  • From autopy.screen.get_color(100, 100) you get tuple like (128, 128, 128) it's already in RGB. If you need it in hex try this:

    autopy.color.rgb_to_hex(*autopy.screen.get_color(100, 100))
    

    EDIT: (2019.09.14)

    Few weeks ago I sent message to author with this problem

    see: mistake in example autopy.color.hex_to_rgb(autopy.screen.get_color(1, 1))

    and now he answered that in next major release this will work as in tutorial.