3.3 - Blocking & Allowing Events

3.3 Blocking & Allowing Events

Some other useful methods to work with events are the set_blocked(), set_allowed(), and get_blocked() events.
set_blocked() takes in a pygame event or a list of events that you want to be blocked from the queue. If you use None as the input, all events will be blocked from the queue.
set_allowed() does the opposite of the previous method. It takes in a pygame event or a list of events that you would like allowed in the queue. If you input None, all events will be allowed.
get_blocked() will return a boolean based on whether or not an event is blocked from the queue. If a list of events is passed in, the method will return True if one of the events is blocked.
# blocks QUIT and KEYUP from the queue pygame.event.set_blocked(pygame.QUIT) pygame.event.set_blocked(pygame.KEYUP) # allows QUIT to the queue pygame.event.set_allowed(pygame.QUIT) print(pygame.event.get_blocked(pygame.QUIT)) # prints False print(pygame.event.get_blocked(pygame.KEYUP)) # prints True
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.