gpt4 book ai didi

python - Pygame def 函数

转载 作者:太空宇宙 更新时间:2023-11-03 18:47:25 30 4
gpt4 key购买 nike

我在 pygame.h 中定义了一些函数。

import time
import pygame, sys
from pygame.locals import*
def screen(a,b,z,v):
screen = pygame.display.set_mode((a,b),z,v)
def image1(a,x,y):
b = pygame.image.load(a).convert()
screen.blit(b,(x,y))

我添加了一些代码:

a = "white.jpg"
screen(50,50,0,32)

但是,我没有像往常一样得到一个窗口。为什么会这样呢?为了使问题更清楚,这就是我得到的:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>

它卡在那里并且无法加载,有时 python 提示符会自行关闭。有人可以解释一下吗?*编辑:我在代码中定义了其他函数。看来定义的函数太多了。如何停止错误?

最佳答案

可能还缺少其他位,但您需要在执行其他操作之前调用pygame.init()

您可以在屏幕函数中添加该调用,或者在主代码中调用它之前:

def screen(a,b,z,v):
pygame.init()
screen = pygame.display.set_mode((a,b),z,v)

pygame.init()
screen(50,50,0,32)

关于python - Pygame def 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19197028/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com