[...] Some systems do not allow the window icon to change after it has been shown. This function can be called before pygame.display.set_mode() to create the icon before the display mode is set.
import pygame
import os
# get the directory of this file
sourceFileDir = os.path.dirname(os.path.abspath(__file__))
iconPath = os.path.join(sourceFileDir, 'reindeer.png')
icon = pygame.image.load(iconPath)
pygame.display.set_icon(icon)
见^{} :
在
pygame.display.set_mode((1600, 900))
之前设置图标:此外,图标的大小受到限制:
如果图标未显示,请尝试使用较小的图标
确保资源(映像)路径和工作目录正确
映像文件路径必须相对于当前工作目录。工作目录可能与python文件的目录不同
文件的名称和路径可以通过^{} 获得。当前工作目录可以通过^{} 获取,也可以通过^{} 更改
另一种解决方案是找到绝对路径。 如果图像相对于python文件的文件夹(甚至在同一文件夹中),则可以获取该文件的目录并连接(^{} )图像文件名。e、 g:
相关问题 更多 >
编程相关推荐