简体   繁体   English

在 PySimpleGUI 中集成 Pygame

[英]Integrate Pygame in PySimpleGUI

I have a game written with a Pygame loop and it currently draws everything happening in the pygame window.我有一个用 Pygame 循环编写的游戏,它目前绘制了 pygame 窗口中发生的一切。 I now want to integrate this window into a larger PySimpleGUI window to have nice functionality around the game.我现在想将这个窗口集成到一个更大的 PySimpleGUI 窗口中,以便在游戏中拥有很好的功能。 Is this possible?这可能吗?

I tried to use the code from here .我尝试使用此处的代码。 The problem is that I get an error like this which comes from VIDEODRIVER at line 25:问题是我在第 25 行收到来自 VIDEODRIVER 的错误:

pygame.error: windib not available

I changed this to 'windows' but then the Pygame window is separated from the PySimpleGUI as a different window.我将其更改为“windows”,但随后 Pygame 窗口作为不同的窗口与 PySimpleGUI 分开。

Can I make the pygame loop as a window INSIDE the PySimpleGUI?我可以将 pygame 循环作为 PySimpleGUI 内部的窗口吗? Thank you.谢谢你。

It looks like the detached window is an open, unresolved issue with pygame 2 .看起来分离的窗口是pygame 2 的一个开放的、未解决的问题

If you're able to downgrade to pygame 1.9.6, the linked demo works as expected on Windows after changing the line 25 to: os.environ['SDL_VIDEODRIVER'] = 'windows' as described.如果您能够降级到 pygame 1.9.6,在将第 25 行更改为: os.environ['SDL_VIDEODRIVER'] = 'windows'后, 链接的演示在 Windows 上按预期工作。

As said there ,正如那里所说,

This line only work on windows:此行仅适用于 Windows:

os.environ['SDL_VIDEODRIVER'] = 'windib'

So make a code to skip it when the os is not Windows.因此,当操作系统不是 Windows 时,请编写代码以跳过它。

import platform
if platform.system == "Windows":
    os.environ['SDL_VIDEODRIVER'] = 'windib'

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

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