2

I have tried looking around a lot for a solution from other questions but I am not sure I could accurately implement them into my program. So I decided to ask here.

Is there a simple way to close a window in pygame whilst keeping pygame opening and able to complete tasks? I use:

pygame.quit()

But it quits the program.

Anyone got an idea?

JayRoy
  • 105
  • 6

1 Answers1

1

do pygame.display.quit() to close the window without leaving pygame

Sven
  • 1,014
  • 1
  • 11
  • 27
  • I have tried this, but in the code I am working on, an error is thrown up that says "display Surface quit". There is still code that needs to run after I close this window, but this error interrupts that. I am not sure how to fix this new problem. Should I attach my code? – JayRoy Mar 25 '20 at 09:25
  • yes please show the error and your code – Sven Mar 25 '20 at 14:18
  • First, I managed to use your advice to clear up the 'display surface quit' error, but now I get another error. I use a elif statement to look for the enter button on the keyboard. When it is pressed, I want the screen I have opened to close, but keep shell running to process a calculation. Instead I get: `pygame.error: video system not initialized` Sorry if this very long – JayRoy Mar 27 '20 at 14:57
  • After you've done ```pygame.display.quit``` you cant run any more commands for your game, so you have to break the game loop – Sven Mar 27 '20 at 15:28
  • this is my problem, I want the GUI to close but I also want to keep SHELL open. What is the best way to do this? – JayRoy Mar 27 '20 at 16:07
  • could you come up with some code – Sven Mar 27 '20 at 16:09
  • I would, but I am unable to pinpoint the error, so the code block I attach would be too large for comment. If it helps, the code that uses the graphics is in a class. This class' rendering function is called in a while loop outside the code. Inside this while loop, there is pygame.display.quit and then the rendering function comes after. The loop looks for a button to be pressed and it is supposed to break the loop and carry on. But this is not the case. – JayRoy Apr 04 '20 at 15:03
  • with ```break()``` you can break out of loops. Maybe you should try that with your loop when you want to close the window. – Sven Apr 04 '20 at 15:17
  • unfortunately, the sensor for the loop is in-fact outside of the loop. It remains in the rendering function that is part of the class. Therefore, I am not sure where I should put the break command. – JayRoy Apr 04 '20 at 17:12
  • just try where the command fits. If it doesn't fit at all, try something like: running = True --------- - if running: pygame.update_function() ---------------- if now_leave_game: running = False – Sven Apr 04 '20 at 18:05