Mac Moj上的Pygame

2024-04-26 13:39:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经使用Python3.7.2、Pyenv和Pygame1.9.4设置了一个开发环境。当执行python文件时,python3 ./main.py我得到一个空白的Pygame屏幕。见下图:

enter image description here

Many other posts suggest that Pygame does not yet work with the macOS Mojave. I'm not sure I believe that.

我的项目中的代码如下所示:

import pygame

WHITE = (255, 255, 255)
RED = (255, 0, 0)

pygame.init()

size = (700, 500)
screen = pygame.display.set_mode(size)

pygame.display.set_caption('My Game')

done = False

clock = pygame.time.Clock()

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

        screen.fill(WHITE)

        pygame.draw.rect(screen, RED, [20, 20, 250, 100], 2)

        pygame.display.flip()

        clock.tick(60)
pygame.quit()

To verify that it was not my code failing, I ran: python3 -m pygame.examples.aliens which opens a blank window and plays music.

有没有人有幸让这个在他们的电脑上运行


Tags: eventpyenvsizethatdisplaynotredscreen
1条回答
网友
1楼 · 发布于 2024-04-26 13:39:05

我在最新操作系统(mojave)上的MacBookPro(2015)上也遇到了同样的问题。 当我遵循关于github问题的说明时,它工作得很好:

https://github.com/pygame/pygame/issues/555(谢谢@ChaseHardin)

这似乎是SDL、暗模式(mojave)、brew和python的问题。
你必须跑:

brew uninstall  force python3

https://www.python.org/downloads/release/python-372/上手动安装python ->;选择python x 64 macos安装程序。在

^{pr2}$

你的屏幕会是红色的。(我的是绿色的,我从来没有这么高兴看到丑陋的绿色在我的生活)。在

相关问题 更多 >