Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pygame freeze at pygame.event.get() when you move/drag the window? [duplicate]

Tags:

python

pygame

Basically I have a loop (tick, set_caption, screen_fill, event.get(), send_frame_event, flip, repeat)

When I drag the window around on windows 7, the loop stops looping, I ended up stuck in pygame.event.get(), I have tried to define certain events only for get e.g. get([pygame.QUIT]) to no avail.

Simply calling pygame.event.clear() has the same freeze effect when dragging/moving the window.

Is there a workaround?

Not full code, but should be enough:

def start(self):
    self.running = True
    Clock = pygame.time.Clock()
    while self.running:
        self.p += 25
        tickFPS = Clock.tick(self.fps)
        pygame.display.set_caption("Press Esc to quit. FPS: %.2f" % (Clock.get_fps()))
        self.screen.fill([self.p&0xFF,(255-self.p)&0xFF,255])
        self.handleEvents()
        self.raiseEvent("updateFrame")
        pygame.display.flip()
def handleEvents(self):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            self.running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                self.running = False

full code at: http://pastie.org/private/wm5vqq3f7xe0xlffy1fq

like image 807
Matthew Parlane Avatar asked Apr 12 '12 11:04

Matthew Parlane


People also ask

What does for event in pygame event get (): do?

for event in pygame. event. get() handles the internal events an retrieves a list of external events (the events are removed from the internal event queue). If you press the close button of the window, than the causes the QUIT event and you'll get the event by for event in pygame.

Why does pygame window not respond?

The window does not respond (freeze), because you do not handle the events. You have to handle the events by either pygame. event. pump() or pygame.

How do you change the window position in pygame?

In os. environ dictionary there is a key SDL_VIDEO_WINDOW_POS to which we can assign x and y value. This will put screen in specific spot in python pygame. Value assigned to X will move the screen in right or left position whereas value assigned to Y will move the screen in up-down position.

What is event loop in pygame?

Pygame will register all events from the user into an event queue which can be received with the code pygame. event. get() . Every element in this queue is an Event object and they'll all have the attribute type , which is an integer representing what kind of event it is.


1 Answers

Try placing a call to pygame.event.pump() inside your mainloop (or handleEvents function)

like image 174
jsbueno Avatar answered Nov 02 '22 23:11

jsbueno