Search code examples
pythonattributeerrorpynput

How to fix "AttributeError(name) from None" when trying to use "Button.Left" in pynput


I am using pynput and am trying to get the mouse to click, for which I import from pynput:

from pynput.mouse import Button, Controller

Then in line 8, I do this:

button = Button.Left

And as a result, I get this error:

Traceback (most recent call last):
  File "C:/FILEPATH.py", line 8, in <module>
button = Button.Left
      File "C:\Program Files (x86)\Python\Python37-32\lib\enum.py", line 346, in __getattr__
raise AttributeError(name) from None
    AttributeError: Left

Do you know what I am doing wrong, or what's missing here?


Solution

  • Just looking at the docs, it should be Button.left with a lowercase l rather than Button.Left with an uppercase l.