Search code examples
pythonsdl-2pysdl2

How To Set The Window Icon PySDL2


I want to set the window icon in PySDL2. I tried doing this

self.icon = sdl2.ext.load_image("./assets/icon.png")
sdl2.SDL_SetWindowIcon(self.window, self.icon)

But since I'm using sdl2.ext.Window it doesn't work.

Any ideas on how I can go about doing this?


Solution

  • Instead of using sdl2.ext, I just imported sdl2 and sdl2.sdlimage. Here is the code if anyone is wondering:

    self.icon = "./icon.png"
    image = sdl2.sdlimage.IMG_Load(self.icon.encode())
    sdl2.SDL_SetWindowIcon(self.window, image)
    sdl2.SDL_FreeSurface(image)