简体   繁体   English

将GUI添加到Pygame应用程序的最佳方法是什么?

[英]What's the best way to add a GUI to a Pygame application?

Are there any good GUIs that support Pygame surfaces as a widget within the application? 在应用程序中是否有任何良好的GUI作为小部件支持Pygame表面?

If this isn't possible or practical, what GUI toolkit has the best graphics component? 如果这不可能或不可行,那么哪个GUI工具箱具有最佳的图形组件? I'm looking to keep the speedy rendering made possible by a SDL wrapper. 我希望通过SDL包装器保持快速渲染成为可能。

Dont use wxPython, its very hard to get to work well with Pygame, as described over at the GUI section of the Pygame wiki. 请勿使用wxPython,这很难与Pygame很好地配合使用,如Pygame Wiki的GUI部分所述。

First of all, pygame relies on the SDL, which means that it can only have one window at a time. 首先,pygame依赖于SDL,这意味着它一次只能有一个窗口。 Thus, trying to implement multiple Gtk, Qt, ... application instances that use pygame, is an impossibility. 因此,尝试实现使用pygame的多个Gtk,Qt,...应用程序实例是不可能的。 The second problematic reason is that those toolkits use their own main loop, which possibly forces you to pipe their events to your pygame instance and vice versa. 第二个有问题的原因是这些工具箱使用它们自己的主循环,这可能迫使您将其事件通过管道传递到pygame实例,反之亦然。 And to mention some other points in short: Drawing the toolkit elements on the pygame window is impossible and the SDL/pygame fullscreen mode will be problematic. 简而言之,还有其他要点:在pygame窗口上绘制工具包元素是不可能的,而SDL / pygame全屏模式将是有问题的。

Instead, opt for any of the libraries listed at the bottom of that page. 相反,请选择该页面底部列出的任何库。 I use pgu myself. 我自己使用pgu

看一下AlbowPGUOcemp

Albow and Ocemp are not being actively maintained. Albow和Ocemp没有得到积极维护。 PGU is now being maintained by Peter Rogers, and Victor Kam has converted most of it to Python 3. PGU现在由Peter Rogers维护,而Victor Kam已将其中的大多数转换为Python 3。

There are 5 pygame GUI toolkits which I've tried to get running under Python 3: Albow, GooeyPy, PGU, pqGUI, and sgc. 我尝试使用5种pygame GUI工具包在Python 3下运行:Albow,GooeyPy,PGU,pqGUI和sgc。 (I didn't get GooeyPy to work with Python 3, but the others did.) (我没有让GooeyPy使用Python 3,但是其他人做到了。)

I ran each of them through a simple Lines-Of-Code counter http://code.activestate.com/recipes/527746-line-of-code-counter/ to gauge their sizes: 我通过一个简单的Lines-Of-Code计数器http://code.activestate.com/recipes/527746-line-of-code-counter/来运行它们,以评估它们的大小:

These are the results: 结果如下:

Albow code        min=2810, max=4551    (max = 162% of min)
Albow\demo        min= 453, max= 649

GooeyPy\gooeypy   min=2034, max=3941    (max = 194% of min)
GooeyPy\examples  min= 178, max= 351

pgu\pgu           min=2910, max=7047    (max = 242% of min)
incl. pgu\pgu\gui min=1678, max=4638    (max = 276% of min)
pgu\examples      min= 822, max=2527

pqGUI.py          min=1586, max=1834    (max = 116% of min)
Example.py        min= 178, max= 225

sgc (incomplete)  min= 889, max=1243    (max = 140% of min)

(I wanted to also try poutine, by Shandy Brown, but I couldn't find it.) (我也想尝试由Shandy Brown创作的poutine,但找不到)。

In each case, the "min" number is more representative of the "size" of the toolkit, since it doesn't count whitespace and comments. 在每种情况下,“最小”数字都更代表工具箱的“大小”,因为它不计算空格和注释。

When the "max" number is very close to the min number, it means that there's not much whitespace and not many comments in the code. 当“最大”数字与最小数字非常接近时,这意味着代码中没有太多空格,也没有太多注释。 pqGUI exemplifies that, because it has almost no comments at all, which is too bad, because (IMO) it makes the nicest-looking widgets. pqGUI举例说明了这一点,因为它几乎根本没有注释,这太糟糕了,因为(IMO)它使外观看起来最漂亮的小部件。

I liked pqGUI because I like the look of the widgets it makes, but it is unsupported and undocumented, and I can't find the author. 我喜欢pqGUI,因为我喜欢它制作的小部件的外观,但是它不受支持且没有记录,所以找不到作者。

Only two of the five are actively maintained/developed: PGU and sgc, and sgc is new and incomplete. 五个活动中只有两个是积极维护/开发的:PGU和sgc,而sgc是新的且不完整。

That makes PGU the clear leader. 这使PGU成为明确的领导者。

Dave 戴夫


PS (10/23/2012) -- I've created a GUI toolkit of my own for PyGame. PS(10/23/2012)-我为PyGame创建了自己的GUI工具包。 It is widget-based, and uses pygame events for communication, so that it can easily be dropped into an existing pygame program, without taking over the event loop. 它基于窗口小部件,并使用pygame事件进行通信,因此可以轻松地将其放入现有的pygame程序中,而无需接管事件循环。 It supports forms, buttons, windows, modal & non-modal message boxes & dialog boxes, vertical menus, text-entry boxes, and sliders (scroll bars). 它支持表单,按钮,窗口,模式和非模式消息框和对话框,垂直菜单,文本输入框和滑块(滚动条)。 It smoothly handles overlapping controls, and forms-within forms. 它可以平滑地处理重叠的控件以及表单内的表单。

However, it's not really complete: it lacks some controls you're likely to want, like file-open dialogs and tables. 但是,它并不是很完整:它缺少一些您可能想要的控件,例如文件打开对话框和表。 The controls that do exist look nice, but features like title-bars & scroll bars are fixed numbers of pixels in width, rather than resizeable. 确实存在的控件看起来不错,但是标题栏和滚动条之类的功能是固定宽度的像素,而不是可调整大小的。 The code is well-commented, and there's a demo app with usage examples, but there's no proper how-to-use documentation. 该代码经过了很好的注释,并且有一个带有用法示例的演示应用程序,但是没有适当的使用方法文档。 And it's pre-beta, so everything is subject to change. 而且是beta版,因此所有内容都可能会发生变化。

If, in spite of those limitations, someone wants to try it out, then contact me by email. 尽管有这些限制,但如果有人想尝试一下,请通过电子邮件与我联系。 Ask about "DavesGUI." 询问“ DavesGUI”。 My email address is here: http://www.burtonsys.com/email/ 我的电子邮件地址在这里: http : //www.burtonsys.com/email/

Here you have an explanation on how to integrate and make interact wxPython and Pygame . 在这里,您将对如何集成wxPythonPygame并使之交互进行说明。

Best GUI toolkit in my opinions is wxPython (a binding for wxWidgets) which has GUI widgets for practically everything including an OpenGL widget and some work has been done with SDL as well. 在我看来,最好的GUI工具包是wxPython (wxWidgets的绑定),它具有几乎包括OpenGL小部件在内的所有GUI小部件,并且SDL也已经完成了一些工作

暂无
暂无

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

相关问题 调试 GUI 应用程序(特别是在 Python 中)的最佳方式? - Best way to debug a GUI application (particularly in Python)? 在没有pygame的情况下监听键保持,键按下和键释放事件的最佳方法是什么 - What's the best way to listen key hold, key press and key release events without pygame 将烧瓶应用程序部署到基于 Windows 的服务器的最佳方法是什么 - What's the best way to deploy flask application to windows based server 添加或减去2个插值曲线的最佳方法是什么? - What's the best way to add or subtract 2 interpolated curves? 将尾部斜杠添加到pathlib目录的最佳方法是什么? - What's the best way to add a trailing slash to a pathlib directory? 在 pygame 中让玩家在每个间隔移动的最佳方法是什么? - What is the best way to make a player move at every interval in pygame? Pygame:从精灵表中显示这些船只及其运动的最佳方式是什么? - Pygame: What is the best way to display these ships and their movement from sprite sheet? 将列表从 python function 导入 tkinter GUI 的最佳方法是什么 - What is the best way to Importing a list from a python function into tkinter GUI 为 selenium 自动化创建 GUI 的最佳方法是什么? - What would be the best way to create a GUI for selenium automation? 向 pygame 绘制方法添加表面位置参数的正确方法是什么? - What is the correct way to add a surface positional argument to the pygame draw method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM