为什么 pygame.display.update() 如果在它之后直接跟随输入,则它不起作用? [英] Why does pygame.display.update() not work if an input is directly followed after it?

查看:105
本文介绍了为什么 pygame.display.update() 如果在它之后直接跟随输入,则它不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我试图在 pygame 中的显示屏幕更新后立即进行输入.我注意到由于某种原因屏幕仅在用户输入输入后更新,尽管输入函数在 pygame.display.update() 之后.为什么会发生这种情况,如何修复代码?

In my program, I'm trying to have an input right after the display screen is updated in pygame. I noticed for some reason the screen is only updated AFTER the user enters in an input, although the input function is after pygame.display.update(). Why does this happen, and how can the code be fixed?

# python 3.6.5
# pygame 1.9.3
def main():
    pygame.draw.rect(screen,[235,235,235],(200,200,200,200))
    pygame.display.update()
    input('')
    # input is shown first instead of the rectangle

我希望矩形先绘制然后输入,但输入先发生,然后屏幕更新

I expected the rectangle to draw first and then the input, but the input occured first and then the screen was updated

推荐答案

致电 pygame.event.pump() pygame.display.update() 之后 input('') 之前>:

Call pygame.event.pump() after pygame.display.update() and before input(''):

def main():
    pygame.draw.rect(screen,[235,235,235],(200,200,200,200))
    pygame.display.update()

    pygame.event.pump()

    input('')

在某些操作系统上,pygame.display.update() 分别为 pygame.display.flip() 不直接更新显示.它只是使显示无效并通知系统更新显示.实际上,在处理事件时会更新显示.
这些事件要么由 pygame.event 处理.pump()pygame.event.get()(在事件循环中使用,但也可以完成这项工作).请注意,此指令不仅处理 IO 或用户事件,还处理一系列运行系统所需的内部事件.

At some OS, pygame.display.update() respectively pygame.display.flip() doesn't update the display directly. It just invalidates the display and notifies the system to update the display. Actually the display is updated when the events are handled.
The events are either handled by either pygame.event.pump() or pygame.event.get() (Which is used in event loops, but would do the job as well). Note this instruction do not only handle the IO or user events, they handle a bunch of internal events too, which are required to run run the system.

并非所有操作系统上的所有实现都具有相同的行为.在某些操作系统上,调用 pygame.display.update() 就足够了,这就是不是每个系统上的每个人都能重现该问题的原因.但在这种情况下,调用 pygame.event.pump() 永远不会错.

Not all implementations on all OS behave the same. At some OS it is sufficient to call pygame.display.update(), that is the reason that not everyone at every system can reproduce the issue. But in this case it is never wrong to call pygame.event.pump().

这篇关于为什么 pygame.display.update() 如果在它之后直接跟随输入,则它不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆