Skip to content
Advertisement

AttributeError: ‘Event’ object has no attribute ‘button’

Here’s my Code and I am just trying run my xbox controller for later on if statements to control dc motors:

JavaScript

I get the error message below when I run my code:

JavaScript

Advertisement

Answer

Each event type generates a pygame.event.Event object with different attributes. The button attribute is not defined for all event objects. You can just get the button attribute from a mouse or joystick event like MOUSEMOTION or MOUSEBUTTONDOWN. However all event objects have a type attribute. Check the event type attribute before the button attribute (see pygame.event):

JavaScript

The MOUSEBUTTONDOWN event occurs once when you click the mouse button and the MOUSEBUTTONUP event occurs once when the mouse button is released. The pygame.event.Event() object has two attributes that provide information about the mouse event. pos is a tuple that stores the position that was clicked. button stores the button that was clicked. Each mouse button is associated a value. For instance the value of the attributes is 1, 2, 3, 4, 5 for the left mouse button, middle mouse button, right mouse button, mouse wheel up respectively mouse wheel down. When multiple keys are pressed, multiple mouse button events occur.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement