Home > other >  Consult: Python with PyautoGUI for RGB value problem
Consult: Python with PyautoGUI for RGB value problem

Time:09-19

I wanted to do a pixel RGB recognition in Python, and find the PyautoGUI module package,
Get the current mouse position RGB function is as follows:
Try:
While True:
# TODO: Get and print the mouse coordinates.
X, y=pyautogui. The position ()
PositionStr="X:" + STR (X). Rjust (4) + 'Y: + STR (Y). Rjust (# 4) rjust (string) method will be to coordinate the right adjustment, let they occupy the same width.
PixelColor=pyautogui. Screenshot (.) getpixel ((x, y))
RGB: positionStr +='(' + STR (pixelColor [0]). Rjust (3)
PositionStr +=', '+ STR (pixelColor [1]). Rjust (3)
PositionStr +=', '+ STR (pixelColor [2]). Rjust (3) +') '
Print (positionStr, end=')
Print (' \ b * len (positionStr), end=', flush=True)
Print (pixelColor)
Except KeyboardInterrupt: # when the user presses ctrl-c, program execution will go to the except clause
Print (' \ ndone ')
1. The code to run normally, but it's wrong to get the RGB value of, the reason is that I open the MAC digital color measurement device in the contrast, I find the mouse the digital system at the current location of the RGB values and color measurement device for RGB value is different, and the difference is very big, not the same,
2. Put the mouse on the screen through different color block, Python get the RGB values have the same case,
So came to the conclusion that the RGB value obtained from the Python is wrong, so I make the following:
1. To obtain the coordinates of the cursor has a problem, I use the rest of the code for the mouse coordinates, real-time found the mouse coordinates acquisition is no problem of
2. The screen resolution of the problem, I change a different screen resolution, and without any improvement in

Request according to the above questions, the great god, where is the problem, still need to introduce other modules or something
  • Related