What module would there be that allows my program to run IF it detects a certain color
for example, if I want my program to type red when #FF0000 pops up on the screen--how can i achieve that. I know how to make python type, i know my conditional statements... i just need to know how to let python grab color.
I think I know what you are looking for
from PIL import ImageGrab
while True:
#gets current image
image = ImageGrab.grab()
#checks which colour a specific spot of your screen has, by coordinates
color = image.getpixel((660, 300))
if color == (255, 0, 0):
print("the color is red")
else:
print("its not red")
Pops up on the screen? The entire screen? A small snippet? A single pixel? It really depends. A basic implementation could be screenshotting on some interval, and parsing each image pixel by pixel to detect the hex code you're looking for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.