Visual Studio code - python- window open the close immediately - Stack Overflow

this is my code my problem is down below, when i run the codeimport pygame as pgfrom OpenGL import *

this is my code my problem is down below, when i run the code

import pygame as pg
from OpenGL import *
from OpenGL.GL import *
from OpenGL.GLU import *
from pygame.locals import *

def Point():
    glBegin(GL_POINTS)
    glVertex3f(0,0,0)
    glEnd()

def main():
    pg.init()

    display=(800, 600)
    pg.display.set_mode(display, DOUBLEBUF|OPENGL)


    gluPerspective(45, (display[0]/display[1]),0.1, 50.0)
    glTranslatef(0.0, 0.0, -5)


    while True:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                pg.quit()
                return
        
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        Point()
        pg.display.flip()
        pg.time.wait(10)
main()

when i run ,the window open then closes immediately my interepter is python 3.10.11

this is my code my problem is down below, when i run the code

import pygame as pg
from OpenGL import *
from OpenGL.GL import *
from OpenGL.GLU import *
from pygame.locals import *

def Point():
    glBegin(GL_POINTS)
    glVertex3f(0,0,0)
    glEnd()

def main():
    pg.init()

    display=(800, 600)
    pg.display.set_mode(display, DOUBLEBUF|OPENGL)


    gluPerspective(45, (display[0]/display[1]),0.1, 50.0)
    glTranslatef(0.0, 0.0, -5)


    while True:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                pg.quit()
                return
        
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        Point()
        pg.display.flip()
        pg.time.wait(10)
main()

when i run ,the window open then closes immediately my interepter is python 3.10.11

Share Improve this question edited Mar 6 at 15:28 ahmad mohammad asked Mar 6 at 15:16 ahmad mohammadahmad mohammad 11 bronze badge 2
  • 1 It is most likely something to do with the pygame functions. Use the debugger to step through the code to see where it goes wrong. – OldBoy Commented Mar 6 at 16:18
  • 1 Unable to reproduce on latest versions of Python, Pygame and OpenGL – Adon Bilivit Commented Mar 6 at 16:21
Add a comment  | 

1 Answer 1

Reset to default 0

Try this:

Snippet:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744966824a4603731.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信