import pygame
pygame.init()
t = time()
Events = pygame.event.get()
print(Events)
end = False
while not end:
if time()-t>3:
print(Events)
Events = pygame.event.get()
t = time()
I wrote the following to know about the event queue in pygame. Here I am waiting for three seconds until the next event.get() is called and in these 3 seconds, I do a lot of events through my keyboard and mouse,
But still I see a blank event queue in the next print ...
Why is it so because if I am not wrong, pygame queues all the events that happen and event.get() returns us the queue and then clears it.
You have to create a Pygame window to get the IO events for the keyboard and mouse:
import pygame
pygame.init()
pygame.display.set_mode((200, 200))
clock = pygame.time.Clock()
end = False
while not end:
clock.tick(1)
events = pygame.event.get()
if events:
print(events)
for event in events:
if event.type == pygame.QUIT:
end = True
pygame.quit()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.