美文网首页Python GUI
三个开源的GUI框架

三个开源的GUI框架

作者: 41ebeb98fa36 | 来源:发表于2018-01-09 19:27 被阅读76次

    最近要编写界面,所以将参考的文章贴出来,并有重点的翻译。本篇文章出自https://opensource.com/resources/python/gui-frameworks

    3 open source Python GUI frameworks

    There comes a time in the journey of most any programmer when they are ready to branch out past the basic examples and start to build a graphical interface to their program.

    In Python, the steps to get started with GUI programming are not terribly complex, but they do require the user to begin making some choices. By its nature as a general purpose programming language with interpreters available across every common operating system, Python has to be fairly agnostic as to the choices it presents for creating graphical user interfaces.

    Fortunately, there are many options available for programmers looking to create an easy way for users to interact with their programs. Bindings exist for several UI frameworks on a variety of platforms, including those native to Windows, Mac, and Linux, and many that will work across all three.

    More Python Resources

    Before we go any further, let me play devil's advocate for just a moment and ask: Does it really make sense for your application to have a traditional graphical user interface at all? For some programs, the answer is obvious. If your application is inherently graphical, and is either optimized for or just makes sense to be run locally on a single local machine, then yes, you probably should consider building a desktop GUI. Many times, this is made obvious by what you're designing.
    这里谈是否需要添加GUI

    But for more general purpose programs, don't count out either the command line or a web interface just yet. The command line offers many advantages—speed, remote access, reusability, scriptability, and control—which may be more important for your application's users than a graphical interface, and there are many libraries like Click, Cement, and Cliff that make it easier to design great command line programs.
    命令行更好用

    Similarly, a web interface, even for a program meant to be run locally, might be an option worth considering, particularly if you think your users may wish to host your application remotely, and projects like Django, Flask, or Pyramid all make this straightforward. You can even use a library like pywebview to put a thin wrapper around a web application in a more native GUI window.
    界面只能locally运行。

    Or you can use a framework like Pyforms to build a consistent experience across the web, command line, and desktop, all with a single code base.
    pyforms建造web上的框架

    Still sure you want to build a GUI? Great, here are three fantastic open source libraries to get you started.
    好了,你愿意建GUI,那就开始吧

    PyQt

    PyQt implements the popular Qt library, and so if you are familiar with Qt development in another language, perhaps from developing native applications for KDE or another Qt-using desktop environment, you may already be familiar with Qt. This opens up the possibility of developing applications in Python which have a familiar look and feel across many platforms, while taking advantage of the tools and knowledge of the large Qt community.
    你会QT吗?会的话那就pyqt了。

    PyQt is dual licensed under both a commercial and GPL license, not unlike Qt project itself, and the primary company supporting PyQt offers a license FAQ to help understand what this means for your application. For another option to use the Qt libraries with Python, consider checking out PySide, which is available under the LPGL.
    参见license,和QT的库有具体的用法

    Tkinter

    If there were a single package which might be called the "standard" GUI toolkit for Python, it would be Tkinter. Tkinter is a wrapper around Tcl/Tk, a popular graphical interface and language pairing first popularized in the early 90s. The advantage of choosing Tkinter is the vast number of resources, including books and code samples, as well as a large community of users who may be able to help you out if you have questions. Simple examples are easy to get started with and fairly human-readable.
    所谓标准的GUI是Tkinter、开发时间早,后援军庞大,有问题有人会帮助解决,好上手

    Tkinter is available under the Python license, on top of the BSD license of Tcl/Tk.

    WxPython

    WxPython brings the wxWidgets cross-platform GUI library from its native C++ to Python. WxPython is a slightly more modern approach to, which looks a little more native than Tkinter across different operating systems as it does not attempt to create its own set of widgets (although these can be themed to look much like native components). It's fairly easy to get started with as well, and has a growing developer community. You may need to bundle wxPython with your applications, as it is not automatically installed with Python.
    语言C++你需要将wxpython与你的应用捆绑在一起。

    Working with Python 3? Check out wxPython's Project Phoenix, a rewrite of the project which will work with the newest version of Python.

    WxPython uses the wxWindows Library License of its parent project, which is OSI approved.


    These are not the only choices you have available to you, not even by a long shot. For more options, check out the "GUI programming in Python" page on the official Python Software Foundation wiki, where you will find dozens of other tools. Solutions are available to bind Python to many different widget libraries and GUI tools like GTK+, FLTK, FOX, and others. While beginners will want to look out for and probably avoid projects which are only partial implementations, or those longer actively maintained, you'll find plenty of good fits for a variety of situations.
    除了以上的还有其他的,参见链接

    While many of the options out there are for more traditional applications that take on the windowed look and feel of their parent desktop environment, there are also times when you may wish to do something completely different, for example, within a video game. There are great libraries for these situations too, like pygame and pyglet.
    视频教程,其他方案
    Do you have a favorite that we didn't mention here? Let us know in the comments below!

    This article was originally published in May 2016 and has been updated with new information.

    About the author

    image

    Jason Baker - Jason is passionate about using technology to make the world more open, from software development to bringing sunlight to local governments. Linux desktop enthusiast. Map/geospatial nerd. Raspberry Pi tinkerer. Data analysis and visualization geek. Occasional coder. Cloud nativist. Follow him on Twitter.

    相关文章

      网友评论

        本文标题:三个开源的GUI框架

        本文链接:https://www.haomeiwen.com/subject/xrpgnxtx.html