[pygame] Very simple program fails. Why?
Sizer
sizer at nospam.com
Wed Apr 27 18:24:04 EDT 2005
"Brent W. Hughes" <brent.hughes at comcast.net> wrote in
news:1tWdneW8RMsvEPPfRVn-og at comcast.com:
> I'm just starting to learn pygame. I write what I think is just about
> the simplest program that should display a window and then quit.
> #-----------------------------------------------
> import sys
> import time
> import pygame
>
> pygame.init()
> screen = pygame.display.set_mode((640,480))
> pygame.display.set_caption("A Bug's Life")
> time.sleep(4)
> #-----------------------------------------------
Two problems here - first is that you should always call
pygame.display.quit() when done. The second is that if you sleep(4)
you've effectively blocked off the event loop for that process, which
makes Windows unhappy. Even clicking 'close' to close the window won't
work. Your very dumbest pygame program should have a loop like:
while pygame.event.poll().type != KEYDOWN:
pygame.time.delay(10)
Which just does nothing (but pumps the event loop) until a key is
pressed, then exits.
Or you could add up the spent time and bail when it hits four seconds, or
whatever you want, but you should be doing something with the
pygame.event loop. And then call the pygame.display.quit() when done of
course.
More information about the Python-list
mailing list