Mac OS X pygame 输入进入终端而不是 Python [英] Mac OS X pygame input goes to Terminal instead of Python

查看:31
本文介绍了Mac OS X pygame 输入进入终端而不是 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过终端在 Mac OS X 上运行基于 pygame 的应用程序.诸如击键之类的输入事件会转到终端而不是我的 Python 应用,并且会被 pygame 检测到.

I'm having trouble running a pygame based app on Mac OS X via Terminal. Input events such as keystrokes go to the Terminal instead of my Python app, and are detected by pygame.

例如,我有以下测试脚本:

For example, I have the following test script:

import pygame

pygame.init()
screen = pygame.display.set_mode((640, 480))

done = False
while not done:
    pygame.event.pump()
    keys = pygame.key.get_pressed()
    if keys[pygame.K_ESCAPE]:
        done = True
    if keys[pygame.K_SPACE]:
        print "got here"

当我从 Mac OS X 终端运行该脚本时,K_ESCAPE 和 K_SPACE 都不会被该脚本处理,但终端会回显空格.

Neither K_ESCAPE nor K_SPACE will be handled by this script when I run it from a Mac OS X Terminal, but Terminal will echo back the spaces.

我正在运行 pygame (py-game) 的 MacPorts 端口,它依赖于 Python 2.4,并且我还使用了 python_select 使 python24 成为活动版本.

I'm running the MacPorts port of pygame (py-game), which depends on Python 2.4, and I've also used python_select to make python24 the active version.

推荐答案

Mac Ports 上的默认 py-game 存在您描述的问题.一种解决方法是安装 py-game2.6 目标.这对我来说适用于 OS X 10.6.7.

The default py-game on Mac Ports has the problem you describe. A work-around is to install the py-game2.6 target instead. This works for me with OS X 10.6.7.

这篇关于Mac OS X pygame 输入进入终端而不是 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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