Thread: Pygame help

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

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Pygame help


    Hello,
    I need help with my pygame. I run the program and it says display is not defined. I'm running python 2.7 on a mac. Here is the program,

    import pygame
    from pygame.locals import *

    screen = pygame.display.set_mode([300, 300])

    while true:
    for event in pygame.event.get():
    if event.type == QUIT:
    pygame.quit

    Thank you.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65
    Code:
    import pygame
    from pygame.locals import *
    
    screen = pygame.display.set_mode([300, 300])
    # nothing shows until you update/flip display 
    pygame.display.flip()
    
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0
    I would do it in your main loop though:

    Code:
    import pygame
    from pygame.locals import *
    
    pygame.init()
    fpsClock = pygame.time.Clock()
    
    screen = pygame.display.set_mode((300, 300))
    
    while True:
    	for event in pygame.event.get():
    		if event.type == QUIT:
    			pygame.quit()
    
    	pygame.display.update()
    	fpsClock.tick(30)
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,892
    Rep Power
    481
    Please test your program, shazer2. On inspection, it doesn't use the flip method.

    My understanding: pygame writes to an offscreen buffer. flip copies the buffer (and possibly only the changed part) to display memory.

    However, flip schedules with the display refresh to avoid interfering with what's being shown. And that's why, opposed to writing your every individual bit directly to display memory, this is a faster method (and in the old days) not snowy.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo