Traceback (most recent call last):
File "G:/Computing/Project/Main.py", line 32, in <module>
ClubsImages, SpadesImages, HeartsImages, DiamondsImages = LoadImages()
File "G:/Computing/Project/Main.py", line 18, in LoadImages
ClubsImages[i] = pygame.image.load(("Images/",x,".png"))
pygame.error: Can't seek in this data source
运行此代码时出现此错误:
def LoadImages():
SpadesImages = {}
ClubsImages = {}
HeartsImages = {}
DiamondsImages = {}
x = 1
for i in range (13):
ClubsImages[i] = pygame.image.load(("Images/",x,".png"))
x+=1
SpadesImages[i] = pygame.image.load(("Images/",x,".png"))
x+=1
HeartsImages[i] = pygame.image.load(("Images/",x,".png"))
x+=1
DiamondsImages[i] = pygame.image.load(("Images/",x,".png"))
x+=1
return ClubsImages, SpadesImages, HeartsImages, DiamondsImages
我之前已经读过这样的文件,除了这是我第一次尝试将它放入数组和循环中。问题不在于循环,所以我已经把它拿出来试了一下,我得到了一个相同的错误。所以我在想它是阵列。我无法看到任何你无法将图像读入数组的原因。
答案 0 :(得分:0)
我很确定问题是你将一个元组传递给pygame.image.load
。根据函数的documentation,它可以采用文件名(作为字符串),或文件对象和可选的名称提示。密切关注您的电话:
pygame.image.load(("Images/", x, ".png"))
您正在传递("Images/", x, ".png")
,这是一个无法解释为文件路径的元组。尝试类似:
pygame.image.load("Images/" + str(x) + ".png")