Pygame 'LEFT' undefined

I am working on a game. I have imported pygame. I am using Python 3.3 and Pygame 3.3. The same error message all the time "LEFT" is not defined. I made exact copies of what was on the Internet as I was already looking for a problem. Here is my code. I tried several different ways and none of them work.

method 1:

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

method 2: (basically everything goes)

 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 about all these methods, I tried to switch between "LEFT" and "pygame.LEFT", etc.

Any ideas?

Very grateful.

0
source share
2 answers

Define LEFT yourself:

 LEFT = 1 

Pygame tutorial I think you follow does just that. In other words, the pygame library has no constants for this value, it is just an integer.

+5
source

As a pointer to Martijn Pieters, the pygame library has no constants for the possible values โ€‹โ€‹of event.button .

Here , I think, is a complete list of possible values โ€‹โ€‹(as a class, so it will not clutter up your global namespace):

 class MouseButtons: LEFT = 1 MIDDLE = 2 RIGHT = 3 WHEEL_UP = 4 WHEEL_DOWN = 5 
+1
source

Source: https://habr.com/ru/post/1238255/


All Articles