How do I change the pygame icon?

前端 未结 3 1824
日久生厌
日久生厌 2020-12-07 01:17

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.

相关标签:
3条回答
  • 2020-12-07 01:58

    If you are using pgzero you can simply set global variable ICON to path to desired PNG file, like:

    ICON = 'images/icon.png'
    

    and pgzero will automatically replace default icon.

    For more information see: https://github.com/lordmauve/pgzero/pull/128/files

    0 讨论(0)
  • 2020-12-07 02:04

    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

    0 讨论(0)
  • 2020-12-07 02:05
    programIcon = pygame.image.load('ikon.png')
    
    pygame.display.set_icon(programIcon)
    
    0 讨论(0)
提交回复
热议问题