## File: README.md # Python GUIs Examples **This repository contains 100s of GUI examples written in Python**. From complete working applications to reusable widgets snippets, these examples can be _freely_ re-used, re-mixed and tweaked to build your own Python GUI applications. ## Contributions Welcome This repo is an _open_ collaborative collection of UI demonstrations, tutorials and examples for Python. **New additions are welcome**, just _fork_ this repository, add your example code file(s) in the [library]/[type]/[folder-name] and open a pull request. ## Browse this repo Examples are available for [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6) and [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6), (many examples) along with [DearPyGui](https://github.com/pythonguis/pythonguis-examples/tree/main/dearpygui), [Flet](https://github.com/pythonguis/pythonguis-examples/tree/main/flet), [Kivy](https://github.com/pythonguis/pythonguis-examples/tree/main/kivy), [NiceGUI](https://github.com/pythonguis/pythonguis-examples/tree/main/nicegui), [PyQt5](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt5) [PySide2](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside2) [Streamlit](https://github.com/pythonguis/pythonguis-examples/tree/main/streamlit) and [Tkinter](https://github.com/pythonguis/pythonguis-examples/tree/main/tkinter) _Not sure which library to use?_ See our [Which Python GUI?](https://www.pythonguis.com/faq/which-python-gui-library/) guide. > Many of these examples have more detailed write-ups on the [Python GUIs website](https://www.pythonguis.com/). See the source code for example to get links to the specific tutorials. If you're new to creating GUI apps check out the introductory [PyQt6 tutorial](https://www.pythonguis.com/pyqt6-tutorial/) or [PySide6 tutorial](https://www.pythonguis.com/pyside6-tutorial/). ## Demo Showcase Some particularly neat examples of UIs build using Python are linked below. The full source code for these examples is available in this repo. In some cases there are also step by step examples of the app being built. 1. Web Browser (untabbed) - "MooseAche" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/browser) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/browser) 1. Web Browser (tabbed) - "Mozzarella Ashbadger" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/browser_tabbed) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/browser_tabbed) 1. Minesweeper - "Moonsweeper" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/minesweeper) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/minesweeper) 1. Notepad - "No2Pads" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/notepad) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/notepad) 1. Calculator - "Calculon" (QtDesigner) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/calculator) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/calculator) 1. Word Processor - "Megasolid Idiom" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/wordprocessor) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/wordprocessor) 1. Webcam/Snapshot - "NSAViewer" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/camera) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/camera) 1. Media Player - "Failamp" [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/mediaplayer) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/mediaplayer) 1. Post-it Notes - "Brown Note" (QtDesigner) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/notes) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/notes) 1. Paint - "Piecasso" (QtDesigner) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/paint) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/paint) 1. Unzip - "7Pez" (QtDesigner) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/unzip) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/unzip) 1. Translator - "Translataarrr" (QtDesigner) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/translate) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/translate) 1. Weather - "Raindar" (QtDesigner) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/weather) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/weather) 1. Currency converter - "Doughnut" (PyQtGraph) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/currency) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/currency) 1. Solitaire - "Ronery" (QGraphicsScene) [PyQt6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyqt6/demos/solitaire) [PySide6](https://github.com/pythonguis/pythonguis-examples/tree/main/pyside6/demos/solitaire) This is just a selection of the demos in this repo, pick a library and look under the demos/ folder. ## Tutorials Alongside the demos we also have step by step tutorial code, taken from our main site at [pythonguis.com](https://www.pythonguis.com). These guide you through building GUIs with PyQt, PySide and other libraries. For example example there is a link back to the tutorial (and vice versa). ## Getting started To use each app you first need to install the requirements. In most cases the only requirements are the GUI library and occasionally requests. To install example specific requirements change to the folder of the example and run: pip3 install -r requirements.txt Once the requirements are installed, you can run the app. Every example in this repo comes with a main Python file called `main.py` to keep things simple. python3 main.py The application window should appear. ## Want to build your own apps? > If you think these apps are neat and want to learn more about take a look at my [PyQt6 tutorial](https://www.pythonguis.com/pyqt6-tutorial) which covers everything you need to know to start building your own applications with Python. You can also find more write-ups and tips [on the same site](http://www.pythonguis.com/). ## Books & Courses This repository and the Python GUIs website are both projects of [Martin Fitzpatrick](https://www.martinfitzpatrick.com) -- hello! I've written a number of popular books & courses on Python GUI programming, which you can find here https://www.pythonguis.com/books Need help with your Python GUI project? I'm [available to hire](https://www.pythonguis.com/hire) ## Licenses All code is **licensed under an MIT license**. This allows you to re-use the code freely, remixed in both commercial and non-commercial projects. The only requirement is to include the same license when distributing. Icons used in the applications are by [Yusuke Kamiyaman](http://p.yusukekamiyamane.com/). --- ## File: pyqt5/tutorials/layouts/README.md # PyQt5 Layouts This folder contains the code examples for the PythonGUIs tutorial [PyQt5 Layouts](https://www.pythonguis.com/tutorials/pyqt-layouts/). --- ## File: pyqt5/tutorials/dialogs/README.md # PyQt5 Dialogs and Alerts This folder contains the code examples for the PythonGUIs tutorial [PyQt5 Dialogs and Alerts](https://www.pythonguis.com/tutorials/pyqt-dialogs/). --- ## File: pyqt5/tutorials/creating-your-first-window/README.md # Creating your first app with PyQt5 This folder contains the code examples for the PythonGUIs tutorial [Creating your first app with PyQt5](https://www.pythonguis.com/tutorials/creating-your-first-pyqt-window/). --- ## File: pyqt5/tutorials/basic-widgets/README.md # PyQt5 Widgets This folder contains the code examples for the PythonGUIs tutorial [PyQt5 Widgets](https://www.pythonguis.com/tutorials/pyqt-basic-widgets/). --- ## File: pyqt5/demos/wordprocessor/README.md # Megasolid Idiom — A rich text editor in PyQt The word processor for all your small, poorly formatted documents. An extension of the notepad, again using a QTextEdit but with rich text editing enabled. The editor supports multiple fonts, styles and paragraph text alignment. There is also support for drag-drop of images, which are automatically opened and embedded. Saves and opens HTML format documents. > If you want to learn more about build GUI applications with Python, take a look at my [PyQt5 tutorials](https://www.pythonguis.com) which covers everything you need to know to start building your own applications with PyQt5. ## Other licenses Icons used in the application are by [Yusuke Kamiyaman](http://p.yusukekamiyamane.com/). --- ## File: pyqt5/demos/weather/README.md # Raindar — A weather forecast app built in PyQt Get your daily weather and 15hr forecast. Data is provided by the free weather and forecast API from https://openweathermap.org/ > If you want to learn more about build GUI applications with Python, take a look at my [PyQt5 tutorials](https://www.pythonguis.com) which covers everything you need to know to start building your own applications with PyQt5. ## Other licenses Icons used in the application are by [Yusuke Kamiyaman](http://p.yusukekamiyamane.com/). They were renamed to match codes generated by OpenWeatherMap. --- ## File: pyqt5/demos/unzip/README.md # 7Pez — the best/worst Unzip application ever created Unzip your files with a cat. Drag-drop your zip file onto the floaty cat, and fill up it's Pez-file repository. Press the head to release the Pez (your files) into the same folder. When you open the application the catty Pez dispenser is empty. Simply drag and drop your .zip file onto the cat to fill it up with Pez. The press the cat's head to release the Pez. > If you want to learn more about build GUI applications with Python, take a look at my [PyQt5 tutorials](https://www.pythonguis.com) which covers everything you need to know to start building your own applications with PyQt5. ## Code notes ### Pez If you know anything about Pez you'll know this application has it the wrong way around. That's because I remembered it wrong, thinking that you pressed the head of a Pez dispenser to make it drop Pez out the bottom. Originally the intention was to make you press the head once for every file you wanted to release, but that was excruciating. It's bad enough as it is. --- ## File: pyqt5/demos/translate/README.md # Translatarrrr — Instant translation from any language to Pirate A translator from any language (supported by Google translate) to pirate. This uses a remote API from http://api.funtranslations.com for English to Pirate translation, and a unofficial Python wrapper around Google translate for other languages to English. The *to English* part uses a Python library built on the web interface, rather than an official API client since it's a faff to set up + non-free. This means this part of the application is not guaranteed to work. The *to Pirate* part uses a public API that is heavily throttled. You'll usually get about 5 translations before the limit kicks in. You can pay for an API key to get more. This is, therefore, very useless. > If you want to learn more about build GUI applications with Python, take a look at my [PyQt5 tutorials](https://www.pythonguis.com) which covers everything you need to know to start building your own applications with PyQt5. --- ## File: pyqt5/demos/solitaire/README.md # Ronery — A Solitaire game in PyQt The classic card Solitaire (Klondike) game with a North Korean / 'Team America: World Police' twist. The game is otherwise identical, offering the same options. Built with PyQt, it uses QGraphicsScene to handle the play area. The classic Solitaire win-screen is also implemented, although since the play canvas is not a bitmap it doesn't "fill up". It's still sufficiently satisfying. The configuration options allow for 3-draw and 1 draw styles, with 3, 5 or infinite rounds. ## Code notes ### Card handling The approach I used here was to treat each place where cards can be placed as a 'stack' object, which handles the cards it currently holds. Each stack is responsible for the layout of the cards on it's pile. A stack is also responsibly for accepting/rejecting an attempted drop of a card on it. Some stacks, e.g. the deck + deal pile do not accept any drop. Others, such as the finish piles, have specific rules. In most cases there is no relationship between any cards on a stack, with the exception of the 'in play' stacks along the bottom. Here cards have a parent-child relationship, allowing multiple cards to be dragged at once. ### The end animation The end-game was a bit weird to implement. Since it is self-contained and happens 'outside' of game time the first thought was to have a separate fake event loop, hitting `QApplication.processEvents` to tick over. But that's nasty. Instead the animation is handled by a QTimer, normally idle during play, which once triggered repeatedly pings an animation step-forward slot. This moves cards (faking 'gravity', bouncing) as well as re-stacking them once they're out of the play area. Restacking uses the normal stacking code so they can pile up. The final piece of the puzzle was to block user interaction, otherwise the cards could still be grabbed and dropped they bounced. The easiest way to achieve this is to place an object over the entire window which is set to capture (and discard) all mouse clicks. ## Other licenses The card images were made from a [freely available set of PNGs](https://github.com/hayeah/playing-cards-assets) which were themselves auto-generated from SVGs traced from actual cards(!). The original card designs are out of copyright. Note that the linked repository contains some custom art on ace cards which may still be copyrighted and so was not used. Icons used in the application are by [Yusuke Kamiyaman](http://p.yusukekamiyamane.com/). > If you want to learn more about build GUI applications with Python, take a look at my [PyQt5 tutorials](https://www.pythonguis.com) which covers everything you need to know to start building your own applications with PyQt5.