繁体   English   中英

Python 启动器没有响应 Pygame

[英]Python Launcher not responding with Pygame

我是 Python 和 Pygame 的新手,现在我正在尝试用一些简单的代码打开一个测试 window:

import pygame, sys

from pygame.locals import *
pygame.init()

DISPLAYSURF = pygame.display.set_mode((400, 300))

pygame.display.set_caption('Hello World!')

while True: # main game loop

    for event in pygame.event.get():

        if event.type == QUIT:
            pygame.quit()

            sys.exit()
    pygame.display.update()

When I try to run it, I get the welcome message in terminal ("pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html "), and the python launcher starts, but it从不打开。 该图标只是在 Dock 中弹跳了一会儿,然后显示应用程序无响应。

Python Launcher initialized normally with other code that doesn't use pygame, and python, pip and pygame are all up to date. 我也尝试过运行教程中的其他代码,但一切都得到相同的结果。 我今天安装了新的 macOS Catalina,如果这有什么不同的话。

谢谢你的帮助!

我遇到了与上面基本相同的代码完全相同的问题,升级 pygame 库解决了这个问题,正如 Tom-cz 在类似问题https://stackoverflow.com/a/60496097/13407487中回答的那样。

如果您在 IDLE 或 python 控制台中运行上述代码,您会看到它导致 Python 启动器挂起(并在扩展坞中弹跳)而没有出现 window:

DISPLAYSURF = pygame.display.set_mode((400, 300))

解决方案是升级 pygame:

python3 -m pip install pygame==2.0.0.dev6

我的设置:MacOS Catalina 10.15.4 Python 3.8.1 pygame 1.9.6 -> 我升级到 2.0.0.dev6

您可以安装 pygame 的特定版本。在提示符下执行此操作:

pip3 install pygame==2.0.0.dev6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM