1

因此,我正在尝试更改我正在开发的游戏的 PyGame 图标。每当我运行代码时,它都会打动我pygame.error: Unsupported image format

pygame 窗口也使用# Setting the game icon 下的代码打开和关闭,当我在代码中没有这些行时,它没有这样做。

我一直在寻找一个好的答案,但我找不到一个好的答案。如果有人有任何建议,我将不胜感激。

我正在使用 Python 3.10 在 Visual Studio Code 上编程

这是我的代码:

import time
import pygame

# Initializes Pygame
pygame.init()

# Game Screen Variables
background_colour = (255,255,255)


# Sets up the playscreen
screen = pygame.display.set_mode((1100,750),0,32)
pygame.display.set_caption("Dusco's Game")
screen.fill(background_colour)
pygame.display.flip()

# Setting the game icon
img = pygame.image.load('gameicon.png')
pygame.display.set_icon(img)


# Game Loop
running = True
while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False

pygame.quit ()
4

1 回答 1

0

确保它是 aPNG并且您执行该路径,因此由于它出错,请尝试以下操作:

img = pygame.image.load('c:/users/USERNAME/PATH_TO_IMAGE/gameicon.png')
于 2021-11-13T00:40:08.903 回答