Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:28:30+00:00 2026-06-13T06:28:30+00:00

I open a pygame window and draw some stuff on it with pyopengl calls

  • 0

I open a pygame window and draw some stuff on it with pyopengl calls something like this:

def run(facets, SCREEN_SIZE=(800, 600)):
  pygame.init()
  screen = pygame.display.set_mode(SCREEN_SIZE, HWSURFACE|OPENGL|DOUBLEBUF)

  glViewport(0, 0, SCREEN_SIZE[0], SCREEN_SIZE[1])
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity()
  gluPerspective(60.0, float(SCREEN_SIZE[0])/SCREEN_SIZE[1], .1, 1000.)
  glMatrixMode(GL_MODELVIEW)
  glLoadIdentity()

  clock = pygame.time.Clock()

  glMaterial(GL_FRONT, GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
  glMaterial(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))

  pygame.mouse.set_visible(False)
  pygame.event.set_grab(True)

  while True:
    for event in pygame.event.get():
      if event.type == QUIT:
        pygame.quit()
        pygame.display.quit()
        print "returning..."
        return
      if event.type == KEYUP and event.key == K_ESCAPE:
        pygame.quit()
        pygame.display.quit()
        print "returning..."
        return

    pygame.mouse.set_visible(False)

    # Clear the screen, and z-buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    # other game loop code here, e.g. rendering the facets
    # and moving the viewport around.

I’ve left in pretty much all the pygame and pyopengl calls I make, in case any of them are relevant.

what I want to happen: to be running a session in bpython/IDLE/interactive python prompt, to call run() and look at something, hit ESC and have it close the window and return me to my prompt.

what actually happens: run my interactive session, build data structures, call run(), look at stuff, hit ESC and the window closes, but then immediately reopens. only way to get out is to kill the python process (which not only kills my interactive session, but in bpython leaves my shell window inoperable.) Note, I also do see the result of print "returning..." in the now defunct shell.

I’ve seen these questions:

  • Why does the pygame window not close properly?
  • Pygame display module init and quit

But they only make me rather paranoid: is pygame really so resource-leaky that you have to quit python to get it to tidy up its mess?

Also, what dark magic is causing my return calls to not return?

Finally, can anyone tell me how to make this work the way I want? even utterly evil unsupported hacks are fine, for now, as I just need to debug my other code using this 3D renderer to see what I’m doing!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:28:32+00:00Added an answer on June 13, 2026 at 6:28 am

    Answer is: always post all of your code!

    This was an indentation error in the calling code, which was calling run() over and over. pygame windows appear to be perfectly happy exiting to an interactive prompt.

    I would also have seen this if I’d had the patience to press ESC 9 times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I open a connection like this: Using conn as New OdbcConnection(connectionString) conn.Open() //do stuff
I open a new window in SSMS and run this: SET ANSI_DEFAULTS ON GO
I open a html page with a myApp.js included like this: <html> <body> ......
Some open source libraries have tendency to re implement basic structures like string, list,
In open source data mining software Weka (written in Java), when I run some
Open-CV 2.4 Android-Java: i have searched for contours (list of MatofPoint) like this: Imgproc.findContours(roi_mat,
window.open() why window.open always pop up with IE , I set firefox is the
Whenever i try and run my pygame program in which I'm trying to load
am I going about this in the correct way? Ive never done anything like
Open Source PHP script for HTTP video streaming? I need some PHP script or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.