我是使用python的新手。自从安装Pygame以来已经有一个星期了,经过多次尝试,当我运行任何程序时,仍然无法启动或打开Pygame窗口。我已经看了尽可能多的教程,并且阅读了所有我能找到的类似问题的文章。我已经复制了在其他网站上找到的所有解决方案,但问题仍然存在。尽管如此,奇怪的是,我正在使用的IDE(Pycharm)很少输出错误消息,而是继续运行但从未启动Pygame窗口。我正在使用安装了python 3.8.1和Pygame版本1.9.6的Pycharm。我正在使用具有High Sierra的Mac。
我非常感谢任何人都能提供的帮助。
下面的代码仅输出pygame版本和“ welcome”消息,但在没有启动窗口的情况下仍可继续运行。
import pygame
(width, height) = (1000, 700)
screen=pygame.display.set_mode((width, height))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
下一个代码块的输出与上面的代码完全相同。
# courtesy of Ene Uran www.daniweb.com
import pygame as pg
pg.init()
screen = pg.display.set_mode((400, 300))
pg.display.set_caption('Draw/fill rectangles using pygame')
white = 0xFFFFFF
red = 0xFF0000
green = 0x00FF00
blue = 0x0000FF
yellow = 0xFFFF00
screen.fill(white, (250, 50, 77, 33))
screen.fill(red, (30, 20, 70, 120))
screen.fill(red, (140, 70, 90, 80))
screen.fill(green, (150, 80, 70, 60))
screen.fill(yellow, (200, 170, 150, 60))
screen.fill(blue, (70, 200, 100, 70))
pg.display.update()
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
raise SystemExit
以下代码块也返回相同的输出:
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 24)
#clock = pygame.time.Clock()
#font = pygame.font.Font(None, 32)
cycles = 0
while True:
pygame.event.get()
screen.fill(0)
# text = font.render('Cycles : %d' % cycles, True, (255, 255, 255))
# screen.blit(text, (100, 100))
cycles += 1
pygame.display.update()
此代码^^来自此问题的原始堆栈溢出论坛:Pygame window not responding after a few seconds
[pygame 1.9.6
不适用于Mac OS上的python 3.8.1
。
有关详细信息,请参见https://github.com/pygame/pygame/issues/555。
尝试安装pygame开发版本,例如pygame == 2.0.0.dev6:
pip3 install pygame==2.0.0.dev6
但是要注意错误。