Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyqt/examples
Learn to create a desktop app with Python and Qt
https://github.com/pyqt/examples
gui pyqt pyqt5 pyqt5-examples pyqt5-tutorial pyside2 python python3 qt qt5
Last synced: 3 days ago
JSON representation
Learn to create a desktop app with Python and Qt
- Host: GitHub
- URL: https://github.com/pyqt/examples
- Owner: pyqt
- Created: 2016-10-13T07:03:35.000Z (over 8 years ago)
- Default Branch: _
- Last Pushed: 2023-08-27T00:37:07.000Z (over 1 year ago)
- Last Synced: 2025-01-03T11:05:24.700Z (10 days ago)
- Topics: gui, pyqt, pyqt5, pyqt5-examples, pyqt5-tutorial, pyside2, python, python3, qt, qt5
- Language: Python
- Homepage:
- Size: 3.62 MB
- Stars: 2,402
- Watchers: 78
- Forks: 580
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- my-awesome-github-stars - pyqt/examples - Learn to create a desktop app with Python and Qt (Python)
README
# PyQt examples 2022
These PyQt examples show you how to create a desktop app with Python and Qt. Start with "Hello World" or browse the official PyQt demos. You can run every example yourself on Windows, Mac or Linux. All you need is Python 3. For instructions, please see [below](#running-the-examples).
| | | | | |
| :--: | :--: | :--: | :--: | :--: |
| Hello World! | Common PyQt Widgets | Layouts | Signals and Slots | Qt Designer & Python || | | | |
| :--: | :--: | :--: | :--: |
| QML Python example | Qt Text Editor | Packaging & deployment | Qt Dark Theme || | | | |
| :--: | :--: | :--: | :--: |
| Action Shooter | Chat Client | Tree Views | Lists || | |
| :--: | :--: |
| Custom Tables | PyQt database example |These examples are taken from the following book:
Python and Qt: The Best Parts
by Michael Herrmann## Official PyQt demos
The [PyQt source archive](https://www.riverbankcomputing.com/software/pyqt/download5) also contains a large number of sample files. You can find them reproduced here in the [`src/pyqt-official`](src/pyqt-official) directory. The easiest way to start them is to follow the [instructions about running examples](#running-the-examples) below, then execute the following commands:
cd src/pyqt-official/qtdemo
python qtdemo.pyThis starts the PyQt example launcher:
You can use it to easily browse and run the official demo applications. The following examples are quite nice for instance:
* Quick / Animation / ColorAnimation
* Graphics Effects / Lighting and Shadows
* Desktop / System Tray
* Desktop / Screenshot
* Widgets / Tetrix## Running the examples
Running the examples is really easy. The only thing you need is [Python 3](https://www.python.org/downloads/).
First, download the [ZIP archive of this repository](https://github.com/pyqt/examples/archive/_.zip) and unpack it. Open a command prompt and use `cd` to navigate into the top-level directory of the archive.
Create a virtual environment via the command:
python3 -m venv venv
This creates the folder `venv/` in your current directory. It will contain the necessary libraries for running the examples.
To activate the virtual environment, use the following command:
```
# On Windows:
call venv\Scripts\activate.bat
# On Mac / Linux:
source venv/bin/activate
```Now execute the following to install the necessary dependencies:
pip install -Ur src/requirements.txt
Once you have done this, use `cd` to navigate to the example you're interested in in the [`src/`](src) folder. For example:
cd "src/01 PyQt QLabel"
You'll find a `.py` file there, typically `main.py`. You can run it with the command:
python main.py
Please note that the virtual environment must still be active for this to work.
## Using PySide
This repository uses PyQt6 to use Qt from Python. Another, alternative binding is PySide6 (also called "Qt for Python"). It is less mature than PyQt6 but has the advantage that you can use it for free in commercial projects.
If you want to use PySide6 instead of PyQt6, simply replace all mentions of the latter by the former. For instance, in [`src/requirements.txt`](src/requirements.txt), replace `PyQt6` by `PySide6`. Similarly for any code examples: `from PyQt6.QtWidgets ...` becomes `from PySide6.QtWidgets ...` etc.
Alternatively, if you don't want to commit to either of the two bindings at this stage, you can also use [Qt.py](https://github.com/mottosso/Qt.py). This is an abstraction over PySide6 and PyQt6. It loads whichever of the two bindings is available. To use it for the examples presented here, replace all mentions of `PyQt6` by just `Qt`.
## Licensing
Except where otherwise indicated, you may use the source code of examples 1 - 15 in the [`src/` directory](src) under the terms of the MIT or GPLv3 licenses.
The official PyQt demos in [`src/pyqt-official`](src/pyqt-official) are [licensed under the GPL](src/pyqt-official/LICENSE).
The screenshots in this repository may be used under the terms of the [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) if you prominently mention and link to [Michael Herrmann's PyQt6 book](https://build-system.fman.io/pyqt6-book).