0

I'm working on a game. I have pygame imported. I am using Python 3.3 and Pygame 3.3. The same error message all the time "LEFT" is not defined. I did exact copies of what were on the internet as I already did a search for the problem. Here is my code. I have tried a few different ways and neither seem to work.

method 1:

import pygame
event = pygame.event.poll()
if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
    ....command

method 2: (basically going all in)

from pygame import *
from pygame.locals import *
import pygame
event = pygame.event.poll()
if event.type == MOUSEBUTTONDOWN and event.button == LEFT:
    ......command

Before telling me, on both those methods I tried switching between "LEFT" and "pygame.LEFT", and so on.

Any ideas?

Hugely appreciated.

Greg Peckory
  • 7,700
  • 21
  • 67
  • 114

2 Answers2

6

Define LEFT yourself:

LEFT = 1

The Pygame tutorial I think you are following does exactly that. In other words, the pygame library has no constants for this value, it's just an integer.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks a million, worked a charm. In my Program (maybe it's new with Pygame 3.3) I had to define RIGHT as 3, and LEFT as 1. But not a big deal thanks for the quick answer. – Greg Peckory Feb 14 '13 at 11:53
  • 1
    +1 There is no predefined constant for the mouse buttons. 1 = Left, 2 = Middle, 3 = Right, 4+5 are the mouse wheel. – Aaron Digulla Feb 14 '13 at 16:20
1

As Martijn Pieters pointed out, the pygame library has no constants for the possible values of event.button.

Here's what I think is a complete list of the possible values (as a class, so it won't clutter your global namespace):

class MouseButtons:
    LEFT = 1
    MIDDLE = 2
    RIGHT = 3
    WHEEL_UP = 4
    WHEEL_DOWN = 5
Community
  • 1
  • 1
n.st
  • 946
  • 12
  • 27