'pyautogui.displayMousePosition() doesn't work in pyautogui
enter code here
Hello!
I tried get the RGB color of the mouse position (like showed in this video https://www.youtube.com/watch?v=TERKvqfySYI) with pyautogui.displayMousePosition(), but it dosent works. This is the code:
import pyautogui as p
import PIL
print(p.displayMousePosition())
this is the console:
...
pyscreeze.PyScreezeException: The Pillow package is required to use this function.
What I've done wrong? How I fix?
Solution 1:[1]
In your code a=p.locateOnScreen('a.png') will return None so replace your code with:
import pyautogui as p
a = p.locateOnScreen('a.png')
while True:
if a != None:
p.click(a)
Solution 2:[2]
The click() function takes a X and Y coordinate as input. The locateOnScreen() function returns values is a 4-integer tuple: (left, top, width, height). So you only need the left and top for the click() function.
Try this:
import pyautogui as p
a = p.locateOnScreen('a.png')
p.click(a[0], a[1])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tanay |
Solution 2 | Jos Damen |