我想在鼠标被点击后运行一个循环。 我启动了一个名为mouse_ched的变量为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)
谢谢! 奥马尔
看起来你的第二个循环甚至没有启动:你启动的鼠标按下错误。因此
一定会在循环开始之前停止循环。 希望这有帮助!在
在回答过快后编辑了
移动你的循环:
在您的版本中,整个循环永远不会启动,因为
mouse_pressed
被初始化为False。在相关问题 更多 >
编程相关推荐