简体   繁体   English

如何设置窗口图标 PySDL2

[英]How To Set The Window Icon PySDL2

I want to set the window icon in PySDL2.我想在 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.但由于我使用的是sdl2.ext.Window它不起作用。

Any ideas on how I can go about doing this?关于我如何去做这件事的任何想法?

There might be a limit to the quality of the image you place as an Icon.您作为图标放置的图像的质量可能会受到限制。

window being sdl2.ext.Window窗口是 sdl2.ext.Window

image = sdl2.ext.image.load_img(path_to_image)

sdl2.SDL_SetWindowIcon(
    window.window,
    image,
)

This code was taken from rubato a pysdl2 wrapper Game Engine for python.此代码取自 rubato 一个 pysdl2 包装器 Game Engine for python。 Check it out here: https://rubato.app/ .在这里查看: https ://rubato.app/。

Edit due to comments:由于评论而编辑:

For your code it would look something like this:对于您的代码,它看起来像这样:

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

You only needed the actual object, stored at self.window.window.您只需要存储在 self.window.window 中的实际对象。 self.window is a pointer? self.window 是一个指针?

Instead of using sdl2.ext, I just imported sdl2 and sdl2.sdlimage.我没有使用 sdl2.ext,而是导入了 sdl2 和 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM