asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.22k forks source link

PyAutoGui/PyScreeze incompatability #328

Open domluther opened 5 years ago

domluther commented 5 years ago

I use coords = pyautogui.locateCenterOnScreen() and it returns a list of the co-ordinates in int64 format.

I then use pyautogui.pixel(coords) on that to try to work out what colour that pixel is and hit an error because pixel() on Windows seems to only handle int and not int64. The relevant error message is..

color = windll.gdi32.GetPixel(hdc, x, y)
ctypes.ArgumentError: argument 3: <class 'TypeError'>: Don't know how to convert parameter 3

Am I using this wrong? The only way I can get around this is to manually cast the returned coords to regular int and then it works perfectly.

paulwrath1223 commented 5 years ago

I Have the same problem, except mine is parameter 2 here is my error message: Traceback (most recent call last): File "C:\Users\anon\Dropbox\Python programs\scratch game bot.py", line 33, in pix = pyautogui.pixel(xco, yco) File "C:\Users\anon\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyscreeze__init__.py", line 447, in pixel color = windll.gdi32.GetPixel(hdc, x, y) ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

Windows 10

qinghao1 commented 4 years ago

Is there any fix for this?

Sai-Prabhav commented 3 years ago

even i have the same problem...

Traceback (most recent call last): File "c:\Users\CSC\Desktop\my code\python\dino.py", line 44, in v = pixel(mp+20, h) File "C:\Users\CSC\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze__init__.py", line 578, in pixel color = windll.gdi32.GetPixel(hdc, x, y) ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

Blues-star commented 3 years ago

the same to me, i got the same error text ` p = tuple(ag.pixel(x, y))

File "C:\Users\P7XXTM1-G\AppData\Roaming\Python\Python37\site-packages\pyscreeze__init__.py", line 578, in pixel color = windll.gdi32.GetPixel(hdc, x, y)

ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2`

ThreePiMatt commented 2 years ago

Ran into this issue myself. It seems that this is only an issue if you have the opencv-python module installed.

michaelkozin commented 2 years ago

same for me, px = pyautogui.pixel(x, y) gives this error: color = windll.gdi32.GetPixel(hdc, x, y) ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

I also have opencv-python installed.

JayRizzo commented 2 years ago

The TypeError might be to receiving a NULL value or None.

I think this might be related to change in default behaviour.

int(None)
# Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
# TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

See my writeup here from another issue i found and created a PR for: https://github.com/asweigart/pyautogui/issues/690#issue-1205346679

TranqStyle commented 8 months ago

I was also having this error:

color = windll.gdi32.GetPixel(hdc, x, y)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

Casting the parameters to int as follows solved my problem: px = pyautogui.pixel(int(x), int(y))