【问题标题】:Pygame window not popping in python using pycharm IDE使用pycharm IDE在python中没有弹出Pygame窗口
【发布时间】:2021-07-09 07:07:00
【问题描述】:

我目前正在尝试使用 Python Crash Course 书来学习 Python,但我现在已经停止,因为我无法继续进行第一个项目。每当我在 pycharm 或 IDLE 中运行程序时,我得到的只是一条消息“pygame 2.0.1 (SDL 2.0.14, Python 3.9.6) 来自 pygame 社区的您好。 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()  

【问题讨论】:

  • 问题不在于你的代码,而在于你的系统。
  • 这个问题可能是你使用的是python 3.9。因为它是最新版本,一些包,可能包括 pygame,可能会损坏。
  • @Rabbid76 哦,我的错,我只是新版本的 python 可能会破坏一些模块,所以我认为是这样。
  • @Rabbid76 我明白了,这可能是python安装的问题吗?非常感谢!
  • 嗯,很奇怪,由于 pygame 无法正常工作,我尝试处理另一个项目(这是关于使用 matplot 库,当我今天再次尝试运行该程序时,它在所有终端中都可以正常工作以及 IDE。我知道一开始出了什么问题,但现在一切正常。非常感谢!

标签: python python-3.x pygame


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多