我希望在之前单击鼠标后运行某个循环。我将一个名为 mouse_clicked 的变量初始化为 false,然后在单击鼠标后将其更改为 True。然而,这似乎并没有让事后进展。这是我的代码:
import sys, pygame
size = width, height = 320, 240
screen = pygame.display.set_mode(size)
running = True
mouse_pressed = False
while running:
while mouse_pressed:
rect = pygame.Rect(10, 20, 30, 30)
pygame.draw.rect(screen, (255,0,0), rect)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pressed = True
if event.type == pygame.QUIT:
running = False
sys.exit(0)
谢谢!奥马尔