In PyGame Event is a class that contain some info about event that have happened in the past. They are stored in queue, so you can simply pull and post events.
pygame.event.Event is not a mistake. Event is a class but pygame.event is a PyGame module. That is because in other languages we would put all event handling routines as static (independent from particular object) class functions, which can be used even when we don't have a single object of this class. To create events use pygame.event.Event(type, dict) or pygame.event.Event(type, **attributes)
Event have only its type, and some atributes. Attributes depends on Event type and are predefined for some types:
ACTIVEEVENT gain, state
KEYDOWN unicode, key, mod
KEYUP key, mod
MOUSEMOTION pos, rel, buttons
MOUSEBUTTONUP pos, button
MOUSEBUTTONDOWN pos, button
JOYAXISMOTION joy, axis, value
JOYBALLMOTION joy, ball, rel
JOYHATMOTION joy, hat, value
JOYBUTTONUP joy, button
JOYBUTTONDOWN joy, button
VIDEORESIZE size, w, h
As you see you can define your own event types if will use only above USEREVENT
To get Event from queue just use pygame.event.get() or get(type) or get(typelist) that gets all, all of given type or all of given types events.
To get only one event each time use pygame.event.poll(). In game it is often used because it will return NOEVENT if there is non.
This routine will wait for evens if queue is empty.
Sometimes only thing that meters for programmer is to know if there are any events in queue. pygame.event.peek() will return True if any.
For debugging purposes of for TDD Its good to see string describing type of event than eventid which is just a number. pygame.event.event_name(type_of_event) will get it for you.
pygame.event.set_grab() will grabb all input only for this application if we are in windowed environment. And pygame.event.get_grab() will test if we have grabbed input.
It is also posible to block unwanted events of given type: pygame.event.set_blocked(type), set_blocked(typelist), set_blocked(NONE)
Be aware that pygame.event.set_blocked(NONE) unlock all events.
pygame.event.get_blocked(type) will return will test if given type is blocked.
pygame.event.set_allowed(type), pygame.event.set_allowed(typelist), pygame.event.set_allowed(None) works similar to pygame.event.set_blocked but in opposite direction and also pygame.event.set_allowed(NONE) will deny all events.
Event queue is a place where goes events from our pygame.time.Cloak but you can define your own events which is very useful. Also you can post events when ever you like by using pygame.event.post(Event).
At the and I present you routine to clear all events from queue: