首页 > 解决方案 > 使用pycharm IDE在python中没有弹出Pygame窗口

问题描述

我目前正在尝试使用 Python Crash Course 书来学习 Python,但我现在已经停止,因为我无法进行第一个项目。每当我在 pycharm 或 IDLE 中运行我的程序时,我得到的只是一条消息,上面写着“pygame 2.0.1 (SDL 2.0.14, Python 3.9.6) Hello from the pygame community. https://www.pygame.org/contribute .html”,没有弹出 pygame 的窗口,我的代码在下面,谢谢谁能帮助我: 编辑:我的操作系统是 Windows 10 21H1,目前使用 pycharm 2021.1 和 python 3.9.6 和 pygame 2.0.1

import sys

import pygame


class AlienInvasion:
    """Overall class to manage game assets and behavior."""

    def __init__(self):
        """Initialize the game, and create game resources."""
        pygame.init()

        self.screen = pygame.display.set_mode((1200, 800))
        pygame.display.set_caption("Alien Invasion")

        # Set the background color.
        self.bg_color = (230, 230, 230)

    def run_game(self):
        """Start the main loop for the game."""
        while True:
            # Watch for keyboard and mouse events.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()

            # Redraw the screen during each pass through the loop.
            self.screen.fill(self.bg_color)

            # Make the most recently drawn screen visible
            pygame.display.flip()


if __name__ == '__main__':
    # Make a game instance, and run the game.
    ai = AlienInvasion()
    ai.run_game()  

标签: pythonpython-3.xpygame

解决方案


已经修复了,我尝试先做另一个项目(一个利用 matplot 库,当我再次尝试时它神奇地修复了。)


推荐阅读