[Python] Window instantly closes when program is run [closed]

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Pygame and pyopengl and i am following this tutorial

    This is my code:

    import pygame as pg
    from OpenGL.GL import *

    class App:
    def __init__(self):
    pg.init()
    pg.display.set_mode((640,480), pg.OPENGL|pg.DOUBLEBUF)
    self.clock=pg.time.Clock()

    #OPENGL Init
    glClearColor(0.1, 0.2,0.2, 1)

    def mainLoop(self):
    running=True
    while running:
    #Checks Events
    for event in pg.event.get():
    if (event.type == pg.QUIT):
    running=False
    #Refresh Screen
    glClear(GL_COLOR_BUFFER_BIT)
    pg.display.flip()

    #Timing
    self.clock.tick(60)

    def quit(self):
    pg.quit()


    if __name__=="__main__":
    myApp=App()


    I dont get any errors just this:

    pygame 2.6.1 (SDL 2.28.4, Python 3.9.0)
    Hello from the pygame community. https://www.pygame.org/contribute.html
    2025-07-23 11:27:54.865 Python[26556:1701460] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/rn/0lbm1p292jlddh1v_4468vw00000gn/T/org.python.python.savedState


    I tried to make a window popup that is slightly black but a window pops up and closes instantly

    Continue reading...

Compartilhe esta Página