python-3.x - Why does Pygame NEED an event handler to function?
问题描述
It makes no sense to me why it's absolutely necessary to make a call to an event handler in order for the screen to be coloured. With the event handler called, the screen is shown green.
Take out the call to the event handler and the screen remains uncoloured - it doesn't even hang in a red state and the loop can still be seen to run continuously. So the addition of an event handler makes all the difference, but WHY?!
import pygame
from pygame.locals import *
clock = pygame.time.Clock()
def event_handler():
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
pygame.quit()
quit()
pygame.init()
screen = pygame.display.set_mode((200,200))
screen.fill((255,0,0)) # red screen
pygame.display.update()
while True:
screen.fill((0,250,0)) # green screen
pygame.display.update()
print("running")
event_handler()
clock.tick(60) # Limit the frame rate.
解决方案
推荐阅读
- c - strsep() 用 '\n' 作为 C 中的分隔符
- c# - SoundEffect.DistanceScale - 如何在 2D 中计算比例?
- c# - WPF ComboBox 项与 XAML 值绑定
- entity-framework - Azure 弹性查询(外部数据源)和实体框架代码优先
- cordova - MediaRecorder - 如何“清除” blob 数据/创建新记录?
- windows - 覆盖文件实际上会覆盖它吗?
- reactjs - Jenkins 在生产服务器上自动构建 Github 存储库
- python - Python - 打印输出时,和+之间的区别
- android - 将选项卡可见性设置为零崩溃应用程序“空引用”
- javascript - 如何将反应状态存储到本地存储中?