mirror of
https://github.com/vinta/awesome-python.git
synced 2026-10-02 08:23:10 +08:00
docs: rewrite GUI Development category intro
The old intro's lead used the same "For a Python X library, use …" template as other category pages, and it carried version-bound usage tips (Qt Widgets vs Qt Quick, pyside6-uic, per-toolkit threading helpers) instead of each project's recommended setup. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,28 +1,33 @@
|
|||||||
For a Python GUI library, use PySide6 for desktop apps, or tkinter to stay on the standard library. For a UI that runs in the browser, use NiceGUI.
|
Among Python GUI libraries, PySide6 is the default for desktop apps and tkinter for small tools. For a UI in the browser, pick NiceGUI.
|
||||||
|
|
||||||
How to choose:
|
How to choose:
|
||||||
|
|
||||||
- A full desktop app: PySide6, or PyQt6 for a codebase already on it
|
- Full desktop app: PySide6, or PyQt6 if your app can be GPL or you buy a license
|
||||||
- A small tool on the standard library alone: tkinter
|
- Small tool without third-party packages: tkinter
|
||||||
- A modern look on top of tkinter: CustomTkinter, or Tkinter Designer to turn a Figma design into tkinter code
|
- Modern look for a tkinter app: [CustomTkinter](https://customtkinter.tomschimansky.com/)
|
||||||
- A GNOME or GTK app: PyGObject
|
- tkinter layout drawn in Figma: [Tkinter Designer](https://github.com/ParthJadhav/Tkinter-Designer)
|
||||||
- Native widgets on Windows, macOS, and Linux: wxPython
|
- Native widgets on Windows, macOS, and Linux: [wxPython](https://wxpython.org/pages/overview/)
|
||||||
|
- GNOME app on Linux: [PyGObject](https://pygobject.gnome.org/)
|
||||||
|
- GPU-rendered tools for your scripts: [Dear PyGui](https://dearpygui.readthedocs.io/en/latest/about/what-why.html)
|
||||||
|
- Multi-touch apps on Android and iOS: Kivy
|
||||||
- Native widgets on desktop and mobile: Toga
|
- Native widgets on desktop and mobile: Toga
|
||||||
- A touch-first app for desktop and mobile: Kivy
|
- One codebase for web, desktop, and mobile: Flet
|
||||||
- Fast, interactive tools with lots of plots: Dear PyGui
|
- Dashboards and web UIs: NiceGUI
|
||||||
- A UI in the browser, or in its own desktop window: NiceGUI
|
- HTML/JavaScript frontend in a desktop window: [pywebview](https://pywebview.flowrl.com/guide/)
|
||||||
- An HTML, CSS, and JavaScript frontend in a native window: pywebview
|
- GUI for an existing argparse script: [Gooey](https://github.com/chriskiehl/Gooey)
|
||||||
- Web, desktop, and mobile apps from one codebase: Flet
|
|
||||||
- A GUI for an existing argparse script: Gooey
|
|
||||||
|
|
||||||
With PySide6, build desktop apps with Qt Widgets, which [respect the system style](https://doc.qt.io/qtforpython-6/faq/whatisqt.html), and save Qt Quick for fluid, touch-style UIs. Lay out windows in Qt Widgets Designer (`pyside6-designer`), then turn each `.ui` file into a Python class with `pyside6-uic`, which the docs call [the standard way](https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html) to use it. To ship the app, the docs recommend `pyside6-deploy` over PyInstaller and similar tools, since it's ["easier to use and also to get the most optimized executable."](https://doc.qt.io/qtforpython-6/deployment/index.html)
|
PySide6 is Qt for Python, the [official Python bindings for Qt](https://doc.qt.io/qtforpython-6/), under the LGPL, the GPL, or a commercial license. Qt's docs [recommend a virtual environment](https://doc.qt.io/qtforpython-6/gettingstarted.html) over installing it into your system Python. Ship it with [pyside6-deploy](https://doc.qt.io/qtforpython-6/deployment/index.html).
|
||||||
|
|
||||||
PySide6 and PyQt6 both bind Qt, so the license usually decides. PySide6 is available under the LGPLv3/GPLv3 and a commercial license. PyQt6 is GPLv3 or commercial, and in Riverbank's words: ["Unlike Qt, PyQt is not available under the LGPL."](https://www.riverbankcomputing.com/software/pyqt/) If your app can't be GPL, PyQt6 means buying a license.
|
PyQt6 wraps the same Qt, but Riverbank [licenses it under the GPL or a commercial license, not the LGPL](https://www.riverbankcomputing.com/software/pyqt/). So a closed-source app needs a commercial PyQt6 license, while PySide6 can stay on the LGPL.
|
||||||
|
|
||||||
With tkinter, import `tkinter.ttk` too and use its themed widgets. Be careful with tutorials: the docs warn that [most documentation you will find online still uses the old API](https://docs.python.org/3/library/tkinter.html) and can be woefully outdated. CustomTkinter adds modern, customizable widgets on top of tkinter, with [a consistent look across all desktop platforms](https://customtkinter.tomschimansky.com/).
|
tkinter is the standard Python interface to Tcl/Tk. Python's docs recommend the [themed tkinter.ttk widgets](https://docs.python.org/3/library/tkinter.ttk.html), which follow the platform's native theme, over the classic ones most online docs still use.
|
||||||
|
|
||||||
NiceGUI serves your UI to the browser by default. Pass `native=True` to `ui.run()` and it [opens in a desktop window](https://nicegui.io/documentation/section_configuration_deployment#native_mode) instead, through pywebview. Use pywebview directly for your own HTML frontend, and pass a Python object as `js_api` to [call its methods from JavaScript](https://pywebview.flowrl.com/guide/interdomain) as `pywebview.api`.
|
NiceGUI runs a web server and shows your UI in the browser, which suits dashboards, micro web apps, and robotics projects. Pass `native=True` to `ui.run()` to [open it in a desktop window](https://nicegui.io/documentation/section_configuration_deployment) instead, or bundle it into an executable with nicegui-pack.
|
||||||
|
|
||||||
Toga, Kivy, and Flet each have their own packager. Toga apps ship with Briefcase, BeeWare's tool for [turning a Python project into a standalone native app](https://briefcase.beeware.org/en/stable/). Kivy [recommends Buildozer](https://kivy.org/doc/stable/guide/packaging-android.html) for Android, and Flet has [`flet build`](https://flet.dev/docs/publish/).
|
Kivy runs the same code on Android, iOS, Linux, macOS, and Windows. Declare the widget tree in the [KV language](https://kivy.org/doc/stable/guide/lang.html) to keep the UI apart from your logic, and build Android packages with [Buildozer](https://kivy.org/doc/stable/guide/packaging-android.html).
|
||||||
|
|
||||||
In any toolkit, keep slow work out of event handlers, or the UI stops responding. The tkinter docs say [long-running computations](https://docs.python.org/3/library/tkinter.html#threading-model) belong in smaller pieces on a timer or in another thread, not in a handler. Run the slow work with Qt's threads and signals, or NiceGUI's `run.io_bound()` and `run.cpu_bound()`. In wxPython and Kivy, hand the result back to the UI thread with `wx.CallAfter()` or `@mainthread`.
|
Toga [uses native system widgets, not themes](https://toga.beeware.org/en/stable/about/philosophy/), so a Toga app is a native app on each platform. Start with the [BeeWare tutorial](https://tutorial.beeware.org/), which packages your app with Briefcase.
|
||||||
|
|
||||||
|
Flet builds web, desktop, and mobile apps from one Python codebase, [without HTML, CSS, or JavaScript](https://flet.dev/docs/). Package it for each platform with [flet build](https://flet.dev/docs/publish/).
|
||||||
|
|
||||||
|
Whatever you pick, keep slow work out of event handlers, or the window freezes. The [tkinter docs](https://docs.python.org/3/library/tkinter.html) say to break it into smaller pieces with timers or run it in another thread, and Qt's docs suggest threads for the same reason.
|
||||||
|
|||||||
Reference in New Issue
Block a user