Skip to content Skip to sidebar Skip to footer

Pygame Program Stops Responding, Giving No Error

so my program is meant to display buttons in rows, then wait for the user to click one, however what would happen is that the it would return to the main menu. I was unsure of how

Solution 1:

When asking for input the program stops and wait until the user types something in. When the program stops it cannot handle events which makes your os to believe the program has crashed. So when using pygame you cannot have console input (unless you create processes).

If all you needed was a delay, you could use a while-loop

def wait(time):
    clock = pygame.time.Clock()

    whiletime > 0:
        dt = clock.tick(30) / 1000# Takes the time between each loop and convert to seconds.time -= dt
        pygame.event.pump()  # Let's pygame handle internal actions so the os don't think it has crashed.

If you want the user to decide how long to wait, you could check for user events

def wait_user_response():
    clock = pygame.time.Clock()
    waiting = Truewhile waiting:
        clock.tick(30)

        foreventin pygame.event.get():
            ifevent.type == pygame.KEYDOWN:  # Or whatever event you're waiting for.    
                waiting = False

There are of course other better ways to go about, but since I don't know how your program functions, this was all I could provide.

Post a Comment for "Pygame Program Stops Responding, Giving No Error"