Home > Enterprise >  How to display the window using a class in pygame?
How to display the window using a class in pygame?

Time:10-26

When running the program there is no error, but the window does not display or show up. There are no errors, but I'm not sure what I could be missing for the window to actually show up.

import pygame as pg

class GAME:
    def __init__(self):
        pg.init()
        self.screen = pg.display.set_mode(WIN)
        self.clock = pg.time.Clock()

    def update(self):
        self.display.flip()
        self.clock.tick(FPS)

    def draw(self):
        self.screen.fill('black')

    def check_events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
                pg.quit()
                exit()

    def run(self):
        while RUN:
            self.check_events()
            self.draw()
            self.update()

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

CodePudding user response:

Thanks to those who commented that I had a typo


class GAME:
    def __init__(self):
        pg.init()
        self.screen = pg.display.set_mode(WIN)
        self.clock = pg.time.Clock()

    def update(self):
        pg.display.flip()
        self.clock.tick(FPS)

    def draw(self):
        self.screen.fill('black')

    def check_events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
                pg.quit()
                exit()

    def run(self):
        while RUN:
            self.check_events()
            self.draw()
            self.update()

if __name__ == '__main__':
    game = GAME()
    game = game.run()
  • Related