python - pygame退出不了
PHP中文网
PHP中文网 2017-04-17 16:09:59
0
1
859

这断代码按下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()....
真心没弄懂

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
黄舟

To exit pygame, call pygame.quit()

pygame generally uses the following code to handle keyboard events:

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"
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template