pygame.display.set_icon(pygame.image obj) 在 python 3.9.1 中不起作用 [英] pygame.display.set_icon(pygame.image obj) doesn't work in python 3.9.1

查看:57
本文介绍了pygame.display.set_icon(pygame.image obj) 在 python 3.9.1 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 python 3.8,一切正常,但是当我将 python 更新到 3.9 时,我发现 pygame.display.set_icon 不起作用:/(没有错误,没有警告)

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)

代码如下:

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 =)

推荐答案

参见 pygame.display.set_icon():

[...] 某些系统不允许窗口图标在显示后更改.可以在pygame.display.set_mode()之前调用这个函数来在设置显示模式之前创建图标.

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

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:

[...] 您可以通过任何表面,但大多数系统都需要 32x32 左右的较小图像.

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

如果图标未显示,请尝试使用较小的图标.

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

此外,您还需要处理事件.请参阅pygame.event.get() 分别 pygame.event.pump():

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.

至少你需要调用pygame.event.pump().

这篇关于pygame.display.set_icon(pygame.image obj) 在 python 3.9.1 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆