pygame mouse.get_pos() not working

泄露秘密 提交于 2019-12-01 18:43:23

Pygame will constantly dispatch events while it's running. These need to be handled in some way or pygame will hang and not do anything. Simplest way to fix it is by adding this to your main loop:

...
    while True:
        for event in pygame.event.get():
            pass                                             
        print pygame.mouse.get_pos()
...
Paco

I never used this before, but I found that

Pygame: Mouse Specific Axis Detection

You need to wait until an event happens. I assume this empties the stack and allows you to get the data later on.

for event in pygame.event.get()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!