是否有可能在 Pygame 中获得完全透明的窗口(通过它看到桌面)? 我已经找到了如何创建一个没有框架的窗口,但似乎没有任何明显的方法可以使其透明。
只要有适用于 Windows 和 Mac OS X 的解决方案,我就愿意结合特定于系统的技术/框架,但我不确定要寻找哪个方向。
我能找到的唯一主题推荐使用wxPython,这不是我的主题可以为这个特定的项目做(需要是 Pygame)。
Is it possible to get a fully transparent window in Pygame (see the desktop through it)? I've found how to create a window without a frame, but there doesn't seem to be any obvious way to make it transparent.
I'd be willing to tie into system-specific technology/frameworks as long as there are solutions for both Windows and Mac OS X, but I'm not sure which direction to be looking.
The only topic I was able to find recommended using wxPython, which isn't something I can do for this particular project (needs to be Pygame).
发布评论
评论(2)
在 Windows 上,您可以创建纯色背景色,然后使用 Win32 API 函数
SetLayeredWindowAttributes()
。 (使用 pywin32 调用)代码:
结果:
说明:
使用透明度颜色的窗口的任何部分都将是完全透明的。 您可以查看游戏窗口后面的任何桌面图标或程序并与之交互。
要移除窗口边框,可以将 Pygame 的显示模式设置为
NOFRAME
。另请参阅:
On Windows, you can create a solid background color then set the window's transparency color with the Win32 API function
SetLayeredWindowAttributes()
. (Called with pywin32)Code:
Result:
Explanation:
Any part of the window using your transparency color will be fully transparent. You can view and interact with any desktop icons or programs located behind your game window.
To remove the window border, you can set Pygame's display mode to
NOFRAME
.See Also:
PyGame 使用 SDL,不支持透明窗口。 尽管至少在 Linux 上使其透明是由窗口管理器而不是应用程序完成的。
PyGame uses SDL, which does not support transparent windows. Although at least on Linux making it transparent is done by the window manager, not the application.