Py学习  »  Python

Python只在while循环中运行一次

Caitlin Lamb • 4 年前 • 340 次点击  
import pygame

r_colour = (200, 100,100)
bg_colour = (0,175,200)
(width, height) = (600, 600)

screen = pygame.display.set_mode((width, height))
screen.fill(bg_colour)
pygame.draw.rect(screen, r_colour, (30, 30, 100, 100), 0)

pygame.display.flip()

running = True
while True:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_s:
                screen.fill(bg_colour)
                pygame.draw.rect(screen, r_colour, (20, 30, 100, 100), 0)
                pygame.display.update()


if running == True:
      for event in pygame.event.get():
          if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_s:
                    screen.fill(bg_colour)
                    pygame.draw.rect(screen, r_colour, (20, 30, 100, 100), 0)
                    pygame.display.update()



while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      break
      running = False



pygame.quit()

试图让红色方块在按下“s”键时移动,不确定为什么它只移动一次然后停止。很新的编程,如果很长/很难阅读,很抱歉。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52779
 
340 次点击  
文章 [ 1 ]  |  最新文章 4 年前