我在参照书中案例学习时,发现在执行pygame.init() 报错如下:
pygame 2.0.1 (SDL 2.0.14, Python 3.7.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Fatal Python error: (pygame parachute) Segmentation Fault
Current thread 0x00007f711a78b700 (most recent call first):
File "/home/zhouyou/projects/FreeTime/marie_adventure/marie.py", line 20 in mainGame
File "/home/zhouyou/projects/FreeTime/marie_adventure/marie.py", line 37 in <module>
[1] 15227 abort (core dumped) /home/zhouyou/anaconda3/bin/python3.7
(base) ➜ FreeTime /home/zhouyou/anaconda3/bin/python3.7 /home/zhouyou/projects/FreeTime/marie_adventure/marie-old.py
pygame 2.0.1 (SDL 2.0.14, Python 3.7.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Fatal Python error: (pygame parachute) Segmentation Fault
Current thread 0x00007f57bc022700 (most recent call first):
File "/home/zhouyou/projects/FreeTime/marie_adventure/marie-old.py", line 193 in mainGame
File "/home/zhouyou/projects/FreeTime/marie_adventure/marie-old.py", line 297 in <module>
[1] 15695 abort (core dumped) /home/zhouyou/anaconda3/bin/python3.7
代码片段如下:
import pygame from pygame.locals import * import sys SCREENWIDTH = 822 # Game screen width SCREENHEIGHT = 199 # Game screen height FPS = 30 # The time to update the screen def mainGame(): global SCREEN, FPSCLOCK score = 0 over = False # define the game go on or not pygame.init() FPSCLOCK = pygame.time.Clock() # control how long for each loops SCREEN = pygame.dispaly.set_mode((SCREENWIDTH, SCREENHEIGHT)) pygame.display.set_caption("玛丽冒险") # title while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() FPSCLOCK.tick(FPS) if __name__ == "__main__": mainGame()