这断代码按下esc键后退出不了
import pygame
from pygame.locals import *
screen = pygame.display.set_mode((600,500))
pygame.init()
while True:
keys = pygame.key.get_pressed()
if keys[K_ESCAPE]:
print 1
exit()
这段代码按下后又可以退出...:
import pygame
from pygame.locals import *
screen = pygame.display.set_mode((600,500))
pygame.init()
while True:
pygame.event.get()
keys = pygame.key.get_pressed()
if keys[K_ESCAPE]:
print 1
exit()
就是多了一句 pygame.event.get()....
真心没弄懂
黄舟2017-04-17 16:11:59
pygame退出要调用pygame.quit()
pygame处理键盘事件一般是使用如下代码:
import pygame as py
py.init()
for event in py.event.get():
if event.type== py.QUIT:
sys.exit()
elif event.type==py.KEYDOWN:
if event.key==py.K_ESCAPE:
print "exit"
sys.exit()
py.quit()
elif event.key==py.K_UP:
print "up"
elif event.key==py.K_LEFT:
print "left"
elif event.key==py.K_DOWN:
print "down"
elif event.key==py.K_RIGHT:
print "right"