【发布时间】:2021-01-20 12:25:32
【问题描述】:
我想用代码更改pygame窗口图标:
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Snake Game")
icon = pygame.image.load('snake icon.png')
pygame.display.set_icon(icon)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
当我使用该代码时它不起作用, 就像窗户自己关闭一样, 但是当我将代码更改为:
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Snake Game")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
它可以工作,但它仍然有默认的 pygame 图标,我想更改 pygame 图标, 谁能告诉我代码有什么问题?
【问题讨论】:
-
你能在控制台中分享异常吗?
-
图标文件名中可能有空格问题,将文件重命名为
snake-icon.png并执行pygame.image.load('snake-icon.png')后是否有效?