I\'ve read similar questions to this on Stack Overflow but they have not helped. Here is my code:
import pygame
from pygame.locals import *
pygame.init()
sc
You should provide the version of pygame and python.
I met the similar issue when I use pygame 1.9.4dev and python 3.6.5
I fix this problem after I downgrade pygame and reinstall python.
NOTE: If you use pyenv, you must make sure --enable-framework option is set when installing python.
# exit current virtualenv
$ pyenv deactivate
# reinstall python
$ PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.5
# And reinstall pygame again.
pip install https://github.com/pygame/pygame/archive/1.9.3.zip
Use the following code to check whether it is work.
import pygame
import sys
def run():
"""Initialize pygame, settings, and screen object."""
pygame.init()
screen = pygame.display.set_mode((300, 200))
pygame.display.set_caption('Keyboard Test')
# main loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
print('KEY pressed is ' + str(event.key) + '.')
# Make the most recently drawn screen visible.
pygame.display.flip()
run()