4️⃣

3.4 - Other Useful Methods

3.4 Other Useful Methods

Other useful methods when working with pygame events are poll(), wait(), peek(), and clear().
poll() will return the first event from the queue. Once used, that event will be removed.
if pygame.event.poll() == pygame.KEYUP: print("Upward!")
wait() will return the first event from the queue, or wait for the next event that occurs. You can pass an integer as a parameter that will specify how long the method will wait for an event.
if pygame.event.wait(1000) == pygame.KEYDOWN: print("Down down down...")
peek() will return a boolean depending on whether or not there are events in the queue. If you pass an event in, the method will check if that event is in the queue. If you pass a sequence of events into the method, it will return True if any one of those events are present in the queue.
print(pygame.event.peek(pygame.KEYDOWN))
clear() will remove event(s) from the given event or sequence of events. If nothing is inputted into the method, all events will be removed from the queue.
pygame.event.clear([pygame.KEYDOWN, pygame.KEYUP])
 
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.