简体   繁体   中英

Python -> Pygame Window Close instatly

i'm follow Clear Code tutorial, and my pygame window closes instantly, i see some guys talking about identation, but i think that's ok.

import pygame, sys
from settings import *

class Game:
    def __init__(self):

        # General Setup
        pygame.init()
        self.screen = pygame.display.set_mode((LARGURA, ALTURA))
        pygame.display.set_caption('Pozzani Rugby Game')
        self.clock = pygame.time.Clock()
    
    def run(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()


            self.screen.fill('black')
            pygame.display.update()
            self.clock.tick(FPS)
    

if __name__ == '__main__':
    game = Game()
    game.run

you need to call the run function like game.run() , if you only say game.run is like just mentioning the function but not invoking it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM