社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python只在while循环中运行一次

Caitlin Lamb • 4 年前 • 348 次点击  
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
 
348 次点击  
文章 [ 1 ]  |  最新文章 4 年前