Searching for pixel color

samwyse dejanews at email.com
Sun Aug 19 08:42:39 EDT 2007


michael maver wrote:
> Hello, I was just wondering if anyone knew of a way to search the screen 
> for a certain color in Python.

I know of lots of ways to do this...

> I know it is possible to do this in other languages, but I'm not sure 
> how I'd go about doing this in Python. Just to let you know, I'm running 
> windows XP and I don't really need it to be a cross platform solution, 
> but if it was that'd be an extra bonus.

... but they are all platform dependent; not just Windows vs Unix, but 
PIL vs wxWin vs whatever.

def search_screen(desired_color):
   root = my_gui.root_window()
   width, height = root.get_size()
   for x in xrange(0, width):
     for y in xrange(0, height):
       if root.get_pixel(x,y) == desired_color:
         return x,y
   return -1, -1

Modify the above using the appropriate values for 'my_gui' and its 
methods, 'root_window', 'get_size' and 'get_pixel'.

 > Thanks very much for taking the time to read this and, hopefully, 
respond!

You're welcome.



More information about the Python-list mailing list