我创建了一个小应用程序来隔离按下空格键时屏幕颜色改变的问题。没有其他箭头键组合导致此问题。当我使用空格键以外的键时,不会出现此问题。应用程序的代码张贴在下面。在
import pygame, sys, time
from pygame.locals import *
pygame.init()
# Set window size and title, and frame delay
surfaceSize = (600, 500)
windowTitle = 'Game'
frameDelay = 0.02
color = "white"
# Create the window
surface = pygame.display.set_mode(surfaceSize, 0, 0)
pygame.display.set_caption(windowTitle)
# Loop forever
while True:
for event in pygame.event.get():
#Quit Game
if(event.type == QUIT):
pygame.quit()
sys.exit()
if(event.type == KEYDOWN):
if(event.key == K_SPACE):
if(color == "white"):
color = "black"
else:
color = "white"
# Refresh the display
surface.fill(pygame.Color(color))
pygame.display.update()
# Set the frame speed by pausing between frames
time.sleep(frameDelay)
抱歉,如果这个问题已经被问过,我找了一会儿,似乎找不到。在
更多地使用以下内容:
。。。在
相关问题 更多 >
编程相关推荐