pygame窗口未在python中使用pycharm ide弹出

velaa5lx  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(308)

我目前正试图使用python速成教程学习python,但我现在已经停止了,因为我无法继续第一个项目。每当我在pycharm或idle中运行我的程序时,我得到的都是来自pygame社区的一条消息:“pygame 2.0.1(sdl 2.0.14,python 3.9.6)您好。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()
kuarbcqp

kuarbcqp1#

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

相关问题