Here are some options.
This is a quick reference not a complete program.
If you mean "read a colour on the screen" as reading a color from some other program, then have you considered a screen capture of that area? Then chose a point on the screen capture to analyze for rgb. Then compare that rgb to the rgb that you are interested in.
Example:
In the following, set the timer for your system to allow for the screenshot to complete before saving to a file.
- import pyautogui, time
-
time.sleep(7)
-
-
screenshot = pyautogui.screenshot()
-
screenshot.save("isitblue.png")
-
Now that you have a saved copy of what you are analyzing, you can directly check outside of your program to see that you grabbed the right image. Use the following or similar:
- #Load and show an image with Pillow
-
from PIL import Image
-
-
#Load the image
-
img = Image.open('isitblue.png')
-
-
#verify that it is in RBG format
-
print(img.mode)
-
#the result should be "RGB"
-
Also,
Python PIL (Python Imaging Library ) and getpixel() Method
getpixel() Returns the pixel (as a single) at x, y.
- # Importing Image from PIL package
-
from PIL import Image
-
-
# creating an image object
-
mypng = Image.open(r"C:\isitblue.png")
-
mypixelcheck = mypng.load()
-
cordinate = x, y = 10, 10
-
-
# using getpixel method
-
print (mypng.getpixel(cordinate));