472,118 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,118 software developers and data experts.

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 1782
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.

Similar topics

4 posts views Thread by grogerteal | last post: by
8 posts views Thread by ofiras | last post: by
1 post views Thread by ofiras | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.