I'm not sure, but after briefly looking through your code I'd guess that
your problem is due to the fact that you test which buttons are down
(none to start) then wait for a click, and then check which button had
been down before the click. You'll probably have better luck using the
event.pos and event.button attributes:
...
for event in pygame.event.get():
...
elif event.type == MOUSEBUTTONDOWN and button == 1:
mousex, mousey = event.pos
...
--Mike
Eric Hunter wrote:
trying to get the box to disappear if you press the right mouse button
inside the box. thanks in advance.
import pygame
from pygame.locals import *
pygame.init()
surface = pygame.display.set_mode((500, 400))
allow = True
while True:
surface.fill((255, 255, 255))
mousex, mousey = pygame.mouse.get_pos()
#if box.collidepoint(mousex, mousey):
#print "Inside the box!"
mpress = pygame.mouse.get_pressed()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
elif event.type == MOUSEBUTTONDOWN and mpress[1]:
mousex, mousey = pygame.mouse.get_pos()
if box.collidepoint(mousex, mousey):
allow = False
if allow == True:
box = pygame.draw.rect(surface, (0, 0, 0), (10, 10,
30, 30), 1)
pygame.display.flip()