pygame输入转到Terminal而不是Python

pygame输入转到Terminal而不是Python

本文介绍了Mac OS X pygame输入转到Terminal而不是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 Terminal运行该脚本时,K_ESCAPE和K_SPACE都不会被该脚本处理,但是Terminal会回显空格.

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游戏具有您描述的问题.解决方法是改为安装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输入转到Terminal而不是Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:55