1

I'm running it through the livewires wrapper which is just training wheels for pygame and other python modules in general; but everytime I run it, it'll execute and when I try to exit, it will not respond and then crash.

Any input on how I could go about fixing this would be great. There isn't any input in my textbook and all google seems to yield are results to this problem using pygame itself.

Apparently pygame and Tkinter seem to conflict?

Thanks in advance!

Addendum - This is the code I was trying to run:

from livewires import games

screen_w = 640
screen_h = 480

my_screen = games.Screen (wid, heit)
my_screen.mainloop()
Louis93
  • 3,843
  • 8
  • 48
  • 94
  • 1
    What do you mean by crash? Does it throw an exception or error? Also, pygame uses SDL and not Tkinter and SDL is known to take a while to shut down. – Zhehao Mao Jun 22 '11 at 14:51
  • 1
    By crash I mean the program becomes unresponsive and I have to go to the task manager to exit it. Also, turns out I shouldn't be running pygame from IDLE, I should be running it straight from Python. Not exactly sure why though, I'd still like to know. Running it from IDLE ensures that the pygame program becomes unresponsive. – Louis93 Jun 22 '11 at 16:03
  • Hmm, that's strange. What happens when you run it outside of IDLE? – Zhehao Mao Jun 22 '11 at 17:39

2 Answers2

4

Similar question: Pygame screen freezes when I close it

There isn't any input in my textbook and all google seems to yield are results to this problem using pygame itself.

Those results probably address the same problem you're having. This is the relevant part of the games.py file from livewires, and nowhere does it call pygame.quit():

def handle_events (self):
    """
    If you override this method in a subclass of the Screen
    class, you can specify how to handle different kinds of
    events.  However you must handle the quit condition!
    """
    events = pygame.event.get ()
    for event in events:
        if event.type == QUIT:
            self.quit ()
        elif event.type == KEYDOWN:
            self.keypress (event.key)
        elif event.type == MOUSEBUTTONUP:
            self.mouse_up (event.pos, event.button-1)
        elif event.type == MOUSEBUTTONDOWN:
            self.mouse_down (event.pos, event.button-1)

def quit (self):
    """
    Calling this method will stop the main loop from running and
    make the graphics window disappear.
    """

    self._exit = 1

def mainloop (self, fps = 50):
    """
    Run the pygame main loop. This will animate the objects on the
    screen and call their tick methods every tick.

    fps -- target frame rate
    """

    self._exit = 0

    while not self._exit:
        self._wait_frame (fps)

        for object in self._objects:
            if not object._static:
                object._erase ()
                object._dirty = 1

        # Take a copy of the _objects list as it may get changed in place.
        for object in self._objects [:]:
            if object._tickable: object._tick ()

        self.tick ()

        if Screen.got_statics:
            for object in self._objects:
                if not object._static:
                    for o in object.overlapping_objects ():
                        if o._static and not o._dirty:
                            o._erase ()
                            o._dirty = 1

        for object in self._objects:
            if object._dirty:
                object._draw ()
                object._dirty = 0

        self._update_display()

        self.handle_events()

    # Throw away any pending events.
    pygame.event.get()

The QUIT event just sets a flag which drops you out of the while loop in the mainloop function. I'm guessing that if you find this file in your Python directory and stick a pygame.quit() after the last line in mainloop, it will solve your problem.

Community
  • 1
  • 1
robots.jpg
  • 5,001
  • 1
  • 38
  • 41
0

I agree. you need to put the whole program (the part to be executed, not the definitions and such) into a while loop.The problem is that pygame is not told to close when exited in IDLE, but outside of IDLE the closure of the program overrides the need to close pygame.

here is the loop:

done = False
while done==False:
    # ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
    for event in pygame.event.get(): # User did something
        if event.type == pygame.QUIT: # If user clicked close
           done=True # Flag that we are done so we exit this loop

    #Main program here

pygame.quit()
Pip
  • 4,387
  • 4
  • 23
  • 31