[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

RE: [pygame] Is there any reason to call sys.exit() to close a pygame program?



I would suggest you to use return instead of sys.exit()

def main():
    window = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("sample")
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                return
        pygame.display.update()

main()

Sent from my Windows Phone

From: Sam Bull
Sent: ‎13-‎08-‎2017 02:06 PM
To: pygame-users@xxxxxxxx
Subject: Re: [pygame] Is there any reason to call sys.exit() to close a pygame program?

On sab, 2017-08-12 at 18:23 +0000, skorpio wrote:
> I usually quit pygame by breaking out of the main loop and calling
> pygame.quit() followed by sys.exit(), but I can't remember anymore
> where I learned to use sys.exit and why it should be used. 

If you need to use an exit function, then I've found using the built-in
exit() function gives an error if you use pyinstaller to create a
frozen binary. That's the only reason I try to use sys.exit(). I've not
had any problems just allowing the execution to reach the end of the
file and completing naturally though.