Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

python - How do I change the pygame icon?

Does anyone know how to change the pygame icon? I found a thing on the pygame website that lets you do this, but when I try it, it just makes the pygame window very small.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First load the icon image as a surface, then use pygame.display.set_icon(surface) to change the icon.

EDIT: Since the asker doesn't know what a surface is

From the docs at http://www.pygame.org/docs/ref/surface.html

"A pygame Surface is used to represent any image. The Surface has a fixed resolution and pixel format. Call pygame.Surface() to create a new image object."

For example, if you used screen = pygame.display.set_mode, screen is a surface.

So when using pygame.display.set_icon(surface) you must first import an image as a pygame.Surface by using a = pygame.image.load('image') where a is the variable the surface will be stored and 'image' is the directory to that image. Then you can set a to the icon by using pygame.display.set_icon(surface). You can pass any surface, but it is desirable that it is 32x32.

More information here: http://www.pygame.org/docs/ref/display.html#pygame.display.set_icon


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...