fmr300
fmr300

Reputation: 9

How to exit stopped Python progam in Pygame 'fullscreen' mode?

I'm developing some Raspberry Pi code - Python in Pygame - and I often want to view it's video-out in fullscreen mode. But since it's in dev, I often run into code errors that stop the Python program - printing the error-info in the Idle shell. But in fullscreen mode, even though the program has stopped, I haven't found a way to exit the screen to get back to Idle.

Anybody know a simple way?

I know I could probably be more defensive in catch-exception blocks, but I would think there's some non programatic way to exit after an error-stop.

Upvotes: 1

Views: 516

Answers (1)

jsbueno
jsbueno

Reputation: 110311

It is a nice place to make use of the try--finally pattern -

If your code have an init function to enter fullscreen, and a main to actually run the game, it could go like that:

import pygame
...

def init():
   global screen
   screen = pyame.display.set_mode(...)
   ...

def main():
   ...

try:
   init()
   main()
finally:
   pygame.quit()

Upvotes: 2

Related Questions