By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

[pygame] Very simple program fails. Why?

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2005-04-26, Brent W. Hughes <br**********@comcast.net> wrote:
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
Jul 19 '05 #2

P: n/a
"Brent W. Hughes" <br**********@comcast.net> wrote in
news:1t********************@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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.