PyGame, window is not closing, tut not helping

Mike Driscoll kyosohma at gmail.com
Thu May 1 12:26:38 EDT 2008


On May 1, 10:55 am, globalrev <skanem... at yahoo.se> wrote:
> im doing this :http://www.learningpython.com/2006/03/12/creating-a-game-in-python-us...
>
> and when closing the program the window stays up and doesnt respond. i
> tried adding this:http://www.pygame.org/wiki/FrequentlyAskedQuestions
>
> bu it doesnt work, or maybe im doing it wrong.
>
> heres the code without the added tutorial exit:
>
> import os, sys
> import pygame
> from pygame.locals import *
>
> if not pygame.font: print 'Warning, fonts disabled'
> if not pygame.mixer: print 'Warning, sound disabled'
>
> class PyManMain:
>     """The Main PyMan Class - This class handles the main
>     initialization and creating of the Game."""
>
>     def __init__(self, width=640,height=480):
>         """Initialize"""
>         """Initialize PyGame"""
>         pygame.init()
>         """Set the window Size"""
>         self.width = width
>         self.height = height
>         """Create the Screen"""
>         self.screen = pygame.display.set_mode((self.width
>                                                , self.height))
>
>     def MainLoop(self):
>         """This is the Main Loop of the Game"""
>         while 1:
>             for event in pygame.event.get():
>                 if event.type == pygame.QUIT:
>                     sys.exit()
>
> class Snake(pygame.sprite.Sprite):
>     """This is our snake that will move around the screen"""
>
>     def __init__(self):
>         pygame.sprite.Sprite.__init__(self)
>         self.image, self.rect = load_image('snake.png',-1)
>         self.pellets = 0
>
> if __name__ == "__main__":
>     MainWindow = PyManMain()
>     MainWindow.MainLoop()

I think the issue is that you're running it from within IDLE. It looks
like pyGame's event loop and Tkinter's event loop interfere with each
other. If you run the scripts from the command line, it works.

Mike



More information about the Python-list mailing list