By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,713 Members | 764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,713 IT Pros & Developers. It's quick & easy.

Searching for pixel color

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.