469,587 Members | 2,659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,587 developers. It's quick & easy.

Searching for pixel color

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

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.

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

__________________________________________________ _______________
Advertisement: Win Dad the Footy Final with Cadbury Favourites!
http://a.ninemsn.com.au/b.aspx?URL=h...adburys&_m=EXT

Aug 19 '07 #1
1 1738
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.
Aug 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.