pyGTK 应用程序中的 pyGame
在 PyGTK 应用程序中使用 PyGame (SDL) 的最佳方式是什么?
我正在寻找一种方法,允许我在 GTK 窗口中拥有绘图区域,同时能够管理 GTK 和 SDL 事件。
What is the best way to use PyGame (SDL) within a PyGTK application?
I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
http://faq.pygtk.org/index.html py?file=faq23.042.htp&req=show 提到了一切:
实现后需要创建一个绘图区域并设置环境变量SDL_WINDOWID:
http://faq.pygtk.org/index.py?file=faq23.042.htp&req=show mentions it all:
You need to create a drawing area and set the environment variable SDL_WINDOWID after it's realized:
有一个简单的解决方案可能适合您。
将 PyGTK 内容和 PyGame 内容编写为单独的应用程序。 然后从 PyGTK 应用程序调用 PyGame 应用程序,使用 os.system 调用 PyGame 应用程序。 如果您需要在两者之间共享数据,那么可以使用数据库、管道或 IPC。
There's a simple solution that might work for you.
Write the PyGTK stuff and PyGame stuff as separate applications. Then from the PyGTK application call the PyGame application, using os.system to call the PyGame application. If you need to share data between the two then either use a database, pipes or IPC.
您可能对此消息线程感兴趣。 看起来他们建议反对。
You may be interested in this message thread. Looks like they recommend against it.
当 PyGame 可以管理自己的窗口,甚至使用整个屏幕时,效果会更好。 GTK 有足够灵活的小部件来允许创建绘图区域。
不过,此页面可能会有所帮助,如果你想尝试一下。
PyGame works much better when it can manage its own window, or even better, use the whole screen. GTK has flexible enough widgets to allow creation of a drawing area.
This page may help, though, if you want to try it.
我自己从未尝试过,但听到很多其他尝试过的人的说法,这不是你想要走的路。
还有一种选择是将 gui 放在 pygame 本身中。 有很多专门为 pygame 构建的 GUI 工具包可供您使用。 其中大多数都尚未完成,但有 2 个大型的、积极维护的: PGU 和OcempGUI。 pygame 网站上的完整列表位于此处。
I've never attempted it myself, but hearing plenty about other people who've tried, it's not a road you want to go down.
There is the alternative of putting the gui in pygame itself. There are plenty of gui toolkits built specifically for pygame that you could use. Most of them are rather unfinished, but there are 2 big, actively maintained ones: PGU and OcempGUI. The full list on the pygame site is here.
不久前我自己尝试这样做,但从未让它完美地工作。 事实上,我从来没有让它在 Windows 下工作过,因为它不断地使整个操作系统崩溃,我失去了耐心。 我继续使用它,因为它只在 Linux 上运行才重要,而且只是一个小项目。 我强烈建议您研究替代方案。 这总感觉像是一种令人讨厌的黑客行为,让我感觉很肮脏。
I tried doing this myself a while ago, and I never got it to work perfectly. Actually I never got it to work at all under Windows, as it kept crashing the entire OS and I ran out of patience. I continued to use it though as it was only important it ran on Linux, and was only a small project. I'd strongly recommend you investigate alternatives. It always felt like a nasty hack, and made me feel dirty.
Sugar 项目有几个使用 PyGTK 和 PyGame 构建的活动。
他们编写了一个支持库来实现此目的,称为 Sugargame。 您应该能够针对常规 PyGTK 应用程序(而不是 Sugar)修改它。
这里有Sugar 开发书中的一章介绍如何使用它。
该库允许 GTK 和 PyGame 之间的事件通信。
享受!
The Sugar project has several Activities built with PyGTK and PyGame.
They wrote a support lib to achieve this, called Sugargame. You should be able to modify it for regular PyGTK apps instead of Sugar.
Here's a chapter in Sugar's development book about how to use it.
The lib allows for communicating events between GTK and PyGame.
Enjoy!