pygame.display.set_icon(pygame.image obj) doesn't work in python 3.9.1

半世苍凉 提交于 2021-02-15 07:18:28

问题


I was using python 3.8 and everything was ok, but when I updated my python to 3.9 I figured out that pygame.display.set_icon doesn't work :/ (No errors, No warnings)

Here's the code:

import pygame
pygame.init()
scr = pygame.display.set_mode((0, 0))
fps = pygame.time.Clock()
pygame.display.set_caption("Caption Here!")
pygame.display.set_icon(pygame.image.load("pics\\img.png"))

fps.tick(60)
pygame.display.update()

the problem is solved. it required a smaller image as it's icon =)


回答1:


See pygame.display.set_icon():

[...] 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.

Set the icon before pygame.display.set_mode((0, 0)):

pygame.display.set_icon(pygame.image.load("pics\\img.png"))

scr = pygame.display.set_mode((0, 0))

In addition, the size of the icon is limited:

[...] You can pass any surface, but most systems want a smaller image around 32x32.

If the icon is not displayed, try a smaller icon.


In addition, you need to handle the events. See pygame.event.get() respectively pygame.event.pump():

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.

At least you need to invoke pygame.event.pump().



来源:https://stackoverflow.com/questions/65454856/pygame-display-set-iconpygame-image-obj-doesnt-work-in-python-3-9-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!