python - Pygame window closes right after
问题描述
import pygame
WIDTH, HEIGHT = 1100, 600
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Game")
WHITE = (255, 255, 255)
def main():
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
WIN.fill(WHITE)
pygame.display.update()
pygame.quit()
if __name__ == "__GAME!__":
main()
When I run this code, the pygame window closes right after while using Virtual Studio Code. While using Jupyter notebook it runs but goes unresponsive after 2-3 seconds. Both of them do not display any errors though.
解决方案
我不确定你为什么使用
if __name__ == "__GAME!__"
但是,如果我将其更改为
if __name__ == "__main__"
然后它工作。
推荐阅读
- c# - 使用 TraceListener 时的 I\O 竞争条件
- c# - 打印学生记录:我想在不同的页面上显示每条记录
- .net-core - 在 Windows 2008 R2 或 2016 中使用 C# 使用反恶意软件扫描接口 (AMSI)
- python - 如何为 MLP 处理 keras 中的可变长度序列?
- angular8 - 如何修复angular 8中的变化检测方法。如何在不手动编写的情况下立即实现检测变化
- rest - 没有可用的工作示例来演示 CucumberJS 与 TestCafe 的集成,显示 RestAPI 测试场景,有人可以建议一种方法吗?
- sql - 如何在 Laravel Eloquent 中添加相关的聚合数据?
- swift - ESP8266 wifi 快速连接
- android - NetworkInfo 已被 API 29 弃用
- c# - .NET Core SSL - 模板仅在浏览器中显示 PR_CONNECT_RESET_ERROR (Firefox)