How to get the color of a pixel in python as fast as possible?


I'm on ubuntu and I want to check every 0.1sec the color of a specific pixel on my screen. How can I do that?

I know about PIL but this would need a full screenshot every 0.1sec just for one single pixel.

Then I found this method using ctypes.windll : Faster method of reading screen pixel in Python than PIL?

But this wont work because I'm not on Windows. Any other idea?

Edit: Solved thanks to b_c

from Xlib import display, X
from PIL import Image #PIL

def getColor(x,y):
    W, H = 1, 1
    dsp = display.Display()
    root = dsp.screen().root
    raw = root.get_image(x, y, W, H, X.ZPixmap, 0xffffffff)
    image = Image.frombytes("RGB", (W, H),, "raw", "BGRX")
    print image.getpixel((0, 0))
asked on Stack Overflow Nov 7, 2019 by noxus Nexus • edited Nov 7, 2019 by noxus Nexus

1 Answer


PIL and other similar programs usually allow you to specify a boundary box to grab smaller amounts

PyAutoGui allows you to take smaller sections

as referenced here code such as

pyautogui.screenshot(region=(0,0, 300, 400))

could be useful

could be useful as well, bbox allows you to only observe a small area.

answered on Stack Overflow Nov 7, 2019 by AlbinoRhino • edited Nov 7, 2019 by martineau

User contributions licensed under CC BY-SA 3.0