[pygame] Very simple program fails. Why?

B

Brent W. Hughes

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)
#-----------------------------------------------
When I run this program from within PythonWin, the Bug's Life window appears
and everything looks okay, but after 4 seconds the window still persists.
When I finally close it using the close box in the upper right of the
window, a box pops up telling me an error occurred ant it wants to send a
report to Microsoft. I click "Don't send" and another box pops up telling
me that the program was trying to access memory location 0x1c.

If I try to run the program stand-alone (outside of PythonWin), a DOS box
pops up for a second or two, then the Bug's Life window flashes up for a
fraction of a second, and then both windows disappear.

Am I doing something wrong?

Brent
 
L

Lee Harr

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)
#-----------------------------------------------
When I run this program from within PythonWin, the Bug's Life window appears
and everything looks okay, but after 4 seconds the window still persists.
When I finally close it using the close box in the upper right of the
window, a box pops up telling me an error occurred ant it wants to send a
report to Microsoft. I click "Don't send" and another box pops up telling
me that the program was trying to access memory location 0x1c.

If I try to run the program stand-alone (outside of PythonWin), a DOS box
pops up for a second or two, then the Bug's Life window flashes up for a
fraction of a second, and then both windows disappear.

Am I doing something wrong?


Works perfectly for me on Linux, but that does not help
you much... If no one helps you out further here, make
your way over to the pygame mailing list. Someone will
be able to spot the problem:
http://pygame.org/info.shtml#maillist
 
S

Sizer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top