Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set an icon on Pygame using a .png file

First, I load my icon image:

icon = pygame.image.load ('apple2.png')

Then I set the icon by using set_icon method:

pygame.display.set_icon (icon)

I run the script, and my icon is not visible.

It shows this instead:

Small icon of a box with a blue bar.

like image 812
Martin Fernandez Avatar asked Jan 01 '26 17:01

Martin Fernandez


1 Answers

This may be because on some operating systems you must set the icon before defining your display. If you set it after defining your display, you may end up with what you have.

"Some systems do not allow the window icon to change after it has been shown." -Pygame Docs (http://pygame.org/docs/ref/display.html#pygame.display.set_icon)

If it starts to work but your icon doesn't look the way you expect it, try making your icon 16x16 or 8x8 and resizing it to 256x256(this may only apply to Windows).

like image 99
Larry McMuffin Avatar answered Jan 03 '26 06:01

Larry McMuffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!