您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python pygame窗口不断崩溃

5b51 2022/1/14 8:20:21 python 字数 1380 阅读 469 来源 www.jb51.cc/python

每当我运行我的代码时,显示的 Python窗口都不会响应. 我的代码有问题还是我必须重新安装pygame和python? 我得到一个黑色的pygame窗口,然后它变成白色,说不响应? 我也是新手,所以请尽可能简单.我试着到处寻找答案,但无法以我能理解的方式得到答案. 请帮帮我.谢谢 :) 1 – 导入库 import pygame from pygame.locals import * 2 – 初

概述

1 – 导入库

import pygame
from pygame.locals import *

2 – 初始化游戏

pygame.init()
width,height = 640,480
screen=pygame.display.set_mode((width,height))

3 – 加载图像

player = pygame.images.load("resources/images/dude.png")

4 – 保持循环

while 1:
    # 5 - clear the screen before drawing it again
    screen.fill(0)
    # 6 - draw the screen elements
    screen.blit(player,(100,100))
    # 7 - update the screen
    pygame.display.flip()
    # 8 - loop through the events
    for event in pygame.event.get():
        # check if the event is the X button
        if event.type==pygame.QUIT:
            # if it is quit the game
            pygame.quit()
            exit(0)

另外,正如@furas所说,它应该是:

player = pygame.image.load("resources/images/dude.png")

不:

player = pygame.images.load("resources/images/dude.png")

这将清除代码中的一些问题.

总结

以上是编程之家为你收集整理的Python pygame窗口不断崩溃全部内容,希望文章能够帮你解决Python pygame窗口不断崩溃所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶