我是 python 编程和 GUI 新手。我在互联网上搜索有关 GUI 编程的信息,发现有很多方法可以做到这一点。我发现Python中GUI最简单的方法可能是tkinter(它包含在Python中,它只是GUI库而不是GUI构建器)?我也读了很多关于 GLADE+PyGTK(和 XML 格式)的内容,有什么特别的(glade 是 GUI 构建器)?
谁能对这个选择发表一些“个人意见”?
我有python代码,我需要制作简单的GUI(2个按钮的打开-关闭-读写,以及一些“打印”工作),然后制作一些.exe文件(是否有最好的选择py2exe=?)。制作 GUI 的代码需要修改很多吗?
非常感谢
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), what is there so special(glade is GUI builder)?
Can anyone make some "personal opinion" about this choices?
I have python code, I need to make simple GUI(2 button's-open-close-read-write,and some "print" work) and then make some .exe file (is there best choice py2exe=?). Is there a lot of changes in code to make GUI?
Many thanks
发布评论
评论(2)
如果您的 GUI 真的那么简单,您应该使用内置的 tkinter。
有一个 Hello, Tkinter 教程,您可以遵循,它非常漂亮直截了当。关于可执行文件的创建, py2exe 在大多数情况下应该可以正常工作(尽管我没有尝试过使用 tkinter)。创建可执行文件的另一种方法是向“setup.py”文件添加一个特殊参数:
例如,这将创建一个可以通过在终端中键入“name-of-executable”来运行的可执行文件(即使在 Windows 上)如果 Python 的“scripts”路径在 PATH 中 ^^)。它运行名为“name_of_package”的模块中的函数“main”。这样,您不必使用 py2exe,而是可以创建 Windows 安装程序或 Debian 软件包等。
对于更复杂的项目,我绝对推荐 PyGTK 和 Glade 作为界面设计师。它需要安装多个 Python 包,以及 GTK+ 安装(这在 Windows 上并不总是那么容易)。 API 很棒,文档齐全,一旦你习惯了,Glade 就非常容易使用GTK 的布局概念。但我的观点有点偏颇,因为我在 PyGTK 中完成了多个项目。 wxWidgets 或 PyQT 是不错的选择。例如,bazaar explorer 是使用 QT 编写的。
If your GUI is really that simple, you should go with the built-in tkinter.
There's a Hello, Tkinter tutorial that you can follow, it's pretty straightforward. Concerning the creation of executables, py2exe should work without problems in most cases (though I haven't tried with tkinter). Another way to create an executable is to add a special parameter to your "setup.py" file:
This would, for example, create an executable that can be run by typing "name-of-executable" into a terminal (even on Windows if Python's "scripts" path is in the PATH ^^). It runs the function "main" in the module called "name_of_package". That way, you don't have to use py2exe but can create a Windows installer, or a Debian package, for instance.
For more complex projects, I can absolutely recommend PyGTK with Glade as interface designer. It requires several Python packages to be installed, plus a GTK+ installation (which is not always that easy on Windows). The API is awesome, well-documented and Glade is very easy to use, once you get used to the layouting concepts of GTK. But my opinion is kind of biased because I've done multiple projects in PyGTK. wxWidgets or PyQT are good alternatives. For example, bazaar explorer is written using QT.
我真的很喜欢 Qt 库的 PyQt 绑定。
什么是 PyQt?
Qt 本身是一个非常好的框架 - 丰富、强大、优雅(至少对我来说)。 PyQt 在将该功能暴露给脚本环境方面做得非常好。
另外,还有一本关于 PyQt 开发的非常好的书 - 使用 Python 和 Qt 进行快速 GUI 编程< /a> - 完成它对我帮助很大。
I really like PyQt bindings for Qt library.
What is PyQt?
Qt itself is a very nice framework - rich, powerfull, elegant (for my taste, at least). And PyQt does a very nice job of exposing that functionality to a scripting environment.
Plus, there is a very nice book about PyQt development - Rapid GUI Programming with Python and Qt - working through it helped me a lot.