Should I use pygame.event.get () or pygame.event.poll ()?

I am making an application in pygame and I need to handle events. I never understood whether to use pygame.event.get() or pygame.event.poll() , or if that really matters.

Question: Should I use pygame.event.get() or pygame.event.poll() ?

+8
python event-handling pygame
source share
1 answer

get() retrieves all the events in the queue in the queue, and is usually used in a loop:

 for event in pygame.event.get(): # use event 

poll() retrieves only one event:

 event = pygame.event.poll() # use event 

In the latter case, you will need to explicitly check if the event type is pygame.NOEVENT ; in the first cycle it simply won’t work if there are no events.

As a rule, the version of get() most often used.

+9
source share

All Articles