Thread: Pygame help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    7
    Rep Power
    0

    Pygame help


    I made a physics sim and I'm trying to add simple graphics. I tried to fill the window with white, but the window stays black until I move another window over it then it turns to white. And when I try to exit the window An error occurs it says:

    Traceback (most recent call last):
    File "filename",
    line 82, in -toplevel-
    if event.type == pygame.QUIT: sys.exit()
    SystemExit

    If you can help thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    It is virtually impossible to diagnose problems with your code if you don't post it up.

    The PyGame problem sounds like you need to refresh/redraw the window after making it white. I do not know the pygame API, but there is probably a function or method to do this that needs to be called.

    As for the other problem, I see from the traceback you are calling sys.exit, which raises a SystemExit exception to exit the program. It is doing exactly what you told it. What did you expect?

    Dave - The Developers' Coach
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    7
    Rep Power
    0
    I'm redrawing the backround so i know its not that. And i expected it to close the window when i try to quit
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Do you call pygame.display.flip() after filling the window with white? You will not see any changes until you call that, since all the graphics are sent to the hidden buffer.

    sys.exit() should exit the system. I have read the Pygame tutorial and I see that their example uses it too, but it is bad programming practice - sys.exit is really for abnormal program termination where you want to return an error code to the OS. It would be better to break out of the loop and let the program flow run to the end. I don't know it that will help or not, since you still have not posted up any source code.

    BTW, I think calling sys.exit from a thread will kill the thread but not kill the application, so don't do that. It can also be trapped by a try: except: clause and ignored, so don't do that either.

    Dave - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo