[pygame] Very simple program fails. Why?

Discussion in 'Python' started by Brent W. Hughes, Apr 26, 2005.

  1. 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
     
    Brent W. Hughes, Apr 26, 2005
    #1
    1. Advertising

  2. Brent W. Hughes

    Lee Harr Guest

    On 2005-04-26, Brent W. Hughes <> 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
     
    Lee Harr, Apr 26, 2005
    #2
    1. Advertising

  3. Brent W. Hughes

    Sizer Guest

    "Brent W. Hughes" <> wrote in
    news::

    > 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.
     
    Sizer, Apr 27, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    480
    Raymond Hettinger
    Jul 27, 2003
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,969
    Smokey Grindel
    Dec 2, 2006
  3. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,299
  4. rantingrick

    [pygame-bug] Pygame.cdrom bug

    rantingrick, Jan 30, 2011, in forum: Python
    Replies:
    1
    Views:
    307
    Benjamin Kaplan
    Jan 30, 2011
  5. Max Norman
    Replies:
    5
    Views:
    138
Loading...

Share This Page