运行程序时pygame窗口没有响应

时间:2018-03-27 16:12:44

标签: pygame window

我一直在制作一个pygame平台游戏并试图运行它购买我的python窗口只是说没有响应然后崩溃是我的代码有什么问题。这是我的代码

链接到我的代码:https://drive.google.com/drive/u/0/folders/1QRNYi2hd5RBhIa-EwKdxdRPUdxWHALon

2 个答案:

答案 0 :(得分:0)

在代码顶部添加:

done=False
while not done:
    #event handler
    for event in pygame.event.get():
        if event.type==QUIT:
            done=True
pygame.quit()

答案 1 :(得分:0)

这是打开窗口的代码,将其更改为红色,然后在按下十字架时将其关闭:

import pygame

#Initialize the game engine 
pygame.init()

red = (255, 0, 0)

#Set width and hight
size = [700, 500]
screen = pygame.display.set_mode(size)

#The caption on top of the window
pygame.display.set_caption("My game")

#Loop until the user clicks the button
done = False

#Manages how fast the screen updates
clock = pygame.time.Clock()

#--------MAIN PROGRAM LOOP--------
while done == False:
    for event in pygame.event.get(): #User did something
        if event.type == pygame.QUIT: #If user clicked close
            done = True

    screen.fill(red)

    pygame.display.flip()

    #Limit to 20 frames per second
    clock.tick(20)

#Exits window if the original loop is broken
pygame.quit()

我希望这有助于

相关问题