【问题标题】:Screen not showing on Mac using pygame使用 pygame 在 Mac 上不显示屏幕
【发布时间】:2020-11-18 05:32:11
【问题描述】:

我正在编写使用 pygame 制作游戏的教程,但在显示屏幕时遇到问题。这是我目前所拥有的:

import pygame

# Initialize the pygame
pygame.init()

# Create the screen, height = 800, width = 600
screen = pygame.display.set_mode((800, 600))

# Game Loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

我安装了 pygame,并且在 PyCharm 中没有错误或警告。当我运行它时(在 PyCharm 和我的终端中),我没有屏幕显示,所发生的只是 python 跑步者的宇宙飞船在我的码头上弹跳。当我在我的电脑上运行这个确切的代码时,它会显示一个黑屏,这是预期的结果。

谁能帮忙,还是我做错了什么?

感谢您的帮助。

【问题讨论】:

    标签: python python-3.x macos pygame


    【解决方案1】:

    我在 Mac 上运行您的代码没有问题。但是,显示的窗口是灰色的,而不是黑色的。

    为了强制显示窗口,可以在创建画面后添加:

    pygame.display.update()
    

    为了找出问题所在,您可能需要在窗口栏中添加一个文本,这可能会生成一条指向您的问题的消息。

    pygame.display.set_caption("Hello world")
    

    【讨论】:

    • 感谢您的回答!两者都不起作用,所以我不确定下一步该做什么。我的问题可能出在 python 或 pygame 上,因为 python 宇宙飞船在我的码头弹跳,并且运行代码没有错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 2017-02-16
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多