python - 使用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()
解决方案
已经修复了,我尝试先做另一个项目(一个利用 matplot 库,当我再次尝试时它神奇地修复了。)
推荐阅读
- excel - 每行的VBA自动填充
- php - ErrorException (E_ERROR) 在 null 上调用成员函数 format()(查看:/home/p4t5z8n7/app-dividendos/resources/views/home.blade.php)
- install4j - Install4j - 有没有办法以编程方式禁用对以前安装的检测?
- ionic-framework - 默认情况下,firebase 是否使用本地存储来保持身份验证状态?
- python - 我制作了一个注册 api 并使用它返回未提供身份验证凭据
- django - 在 Django ORM 中,它们是否等同于 EntityFramework 命令 EnsureCreated 和 EnsureDeleted?
- regex - Solr 过滤点/句号,除非它以某些短语开头
- jpa - JPA:将两个字段设为唯一键或让 jpa 更新但不插入
- python - 使用 while 循环将用户输入写入文件
- python - 即使条件为真,if 语句也没有在函数内执行