Search code examples
pythonscreenshotscreen-capture

ImageGrab.grab(bbox()) doesn't return RGB values


This is my code:

import pyscreenshot as ImageGrab


class Main:
    px = ImageGrab.grab(bbox=[799, 449, 800, 450]).load()

However, when I print px[0, 0] it returns me just an int, not an RGB triplet. Anyone knows why that is?


Solution

  • Does this code work for you (you will need to install MSS first):

    import mss
    
    with mss.mss() as sct:
        img = sct.grab((799, 449, 800, 450))
        print(img.pixel(0, 0))
    

    In my terminal:

    $ python3 test.py                                                                     
    (30, 30, 30)