Pygame 窗口在打开时冻结

编程入门 行业动态 更新时间:2024-10-25 07:29:22
本文介绍了Pygame 窗口在打开时冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在学习如何使用 pygame,我只是想为我正在创建的游戏打开一个窗口.

程序编译得很好,我试着画一个圆圈,看看这是否会改变任何东西,但在这两种情况下,我仍然只是得到一个冻结的空白窗口.我的电脑有足够的存储空间,只打开了 2 个应用程序,但这是唯一一个卡住的应用程序.

导入pygamepygame.init()窗口 = pygame.display.set_mode((500, 500))

我必须强制退出 Python,因为它停止响应.我有 Python 3.7.4 版和 Pygame 1.9.6 版.

有什么建议吗?

解决方案

一个最小的、典型的 PyGame 应用程序

  • 需要一个游戏循环

  • 必须通过

    导入pygamepygame.init()窗口 = pygame.display.set_mode((500, 500))# 主应用程序循环运行 = 真运行时:# 事件循环对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:运行 = 错误# 清除显示window.fill(0)# 绘制场景pygame.draw.circle(window, (255, 0, 0), (250, 250), 100)# 更新显示pygame.display.flip()

    I'm learning how to use pygame, and I'm just trying to open up a window for the game I'm creating.

    The program compiles fine, and I tried drawing a circle to see if that would change anything but in both scenarios I still just get a blank window that freezes. My computer has plenty of storage space and only 2 applications open, and yet this is the only application that is freezing.

    import pygame pygame.init() window = pygame.display.set_mode((500, 500))

    I have to force quit Python because it stops responding. I have Python version 3.7.4 and Pygame version 1.9.6.

    Any advice?

    解决方案

    A minimal, typical PyGame application

    • needs a game loop

    • has to handle the events, by either pygame.event.pump() or pygame.event.get().

    • has to update the Surface whuch represents the display respectively window, by either pygame.display.flip() or pygame.display.update().

    See also Python Pygame Introduction

    Simple example, which draws a red circle in the center of the window:

    import pygame pygame.init() window = pygame.display.set_mode((500, 500)) # main application loop run = True while run: # event loop for event in pygame.event.get(): if event.type == pygame.QUIT: run = False # clear the display window.fill(0) # draw the scene pygame.draw.circle(window, (255, 0, 0), (250, 250), 100) # update the display pygame.display.flip()

更多推荐

Pygame 窗口在打开时冻结

本文发布于:2023-11-17 07:33:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   Pygame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!