J.Lim
J.Lim

Reputation: 13

pyautogui.pixel picking up color from upper left of actual position

while True:
 x=pyautogui.position()
 print(x+pyautogui.pixel(x[0],x[1]))

and program is picking up color that is actually upper left of my cursor...

I am using python 3.6, windows 10, on 125% magnification. is this one of the reason?

Upvotes: 0

Views: 12067

Answers (2)

user7711283
user7711283

Reputation:

Usually picking color with the mouse gives NOT the color of the mouse pointer on the screen but the color of the screen 'below' the cursor.

On my box (Linux Mint) the code:

import pyautogui
while True: 
    posXY = pyautogui.position() 
    print(posXY, pyautogui.pixel(posXY[0], posXY[1]) )
    if posXY[0] == 0:
        break

delivers what it should - the color 'below' the mouse pointer.

Notice the 'break' in the endless loop. This allows you to stop the loop by moving the mouse to the left edge of the screen :)

Upvotes: 3

Kathir
Kathir

Reputation: 1362

I have the same setup as yours (but Python 3.7) and faced the very same issue.

Why it occurred? Every now and then I connect and disconnect the external monitor from my laptop. This causes certain scaling issues every time. So, I tried restarting my computer with the external monitor connected and did not disconnect it until I ran this script. It worked like a charm. BTW, I also tried just restarting the Windows Explorer, but this did not resolve the issue.

tldr; Restart your PC and do not modify the display configuration since the restart

Upvotes: 0

Related Questions