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.45k stars 1.26k forks source link

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

Open TheBMaxus opened 3 years ago

TheBMaxus commented 3 years ago

I'm trying to check a certain pixel and see if it's color matches a certain RGB tone. This is the line that gives the error:

if pyautogui.pixelMatchesColor(hisLeft + 48, hisTop + 128, (0, 95, 0)) is True:

This is the error that prints out on the console:

Traceback (most recent call last): File "C:\Users\User\PycharmProjects\Project\m.py", line 196, in status() File "C:\Users\User\PycharmProjects\Project\m.py", line 26, in status buy() File "C:\Users\User\PycharmProjects\Project\m.py", line 144, in buy if pyautogui.pixelMatchesColor(hisLeft + 48, hisTop + 128, (0, 95, 0)) is True: File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\pyscreeze__init.py", line 589, in pixelMatchesColor pix = pixel(x, y) File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\pyscreeze\init__.py", line 608, in pixel color = windll.gdi32.GetPixel(hdc, x, y) ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

I tried to look online, and I didn't find much on this error, and the only fix that I found didn't work. Does anyone know the problem?

Applehihi commented 2 years ago

I've encountered this error too What I did which worked was to convert the arguments to int explicitly (although I am not sure why this is needed). e.g.

return pyautogui.pixelMatchesColor(int(x), int(y), (214, 190, 0), tolerance=10)