I am trying to capture the MOUSEBUTTONDWON and MOUSEBUTTONUP events seperately to help me with my click and drag code. But when press the mouse button down the event is also captured by the pygame.MOUSEBUTTONUP event!
The code is located below:
import pygame
LEFT = 1
开发者_高级运维running = 1
screen = pygame.display.set_mode((320, 200))
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
print "You pressed the left mouse button at (%d, %d)" % event.pos
elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
print "You released the left mouse button at (%d, %d)" % event.pos
screen.fill((0, 0, 0))
pygame.display.flip()
When I click the left mouse button down both the statements are printed when they shouldn't be.
Any idea why this happens?
Your problem could be because you have a problem Pygame installation. Reinstall Pygame.
Try this link instead of the one on the official website: link. Make sure that you download the installer for the version of Python you are using, as well as the amount of bits you installed Python in. You can get the version of Python by loading up the interpreter, and looking at the top line that reads something like:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [XXXXXXXXXXXXXXXXXXXXXX] on win32
Where the version number is on the left, and the number of bits are on the right.
精彩评论