[introduction]: do you want to make your own desktop application? Here are 15 examples to get you started.
This time, we will introduce a collection of 15 small desktop applications written in pyqt framework and python.
The address of this open source project is:https://github.com/learnpyqt/…
These apps will showcase various parts of the QT framework, including advanced widgets, multimedia, graphical views, and non decorative windows. Of course, the most interesting / distinctive and fully functional applications are mine sweeping, solitaire and drawing.
- Web browser(no tab) – “mooseache”
- Web browser(TAB) – “mozzarella ashpacker”
- mine clearance-“Moonsweeper”
- text editor-“Megasolid Idiom”
- Camera / snapshot-“NSAViewer”
- Notes-“Brown Note”（QtDesigner）
- decompression -“7Pez”（QtDesigner）
- Currency converter-“Doughnut”（PyQtGraph）
Installation and use
To use these apps, you first need to install the requirements file. In most cases, the only thing to install is pyqt5, and occasionally other dependencies. If you want to install some app specific dependencies, enter the app folder and run the following code:
pip3 install -r requirements.txt
After installation, you can use Python 3 to execute
The application window appears.
1. Web browser (no tab)
Mooseache: when the browser was invented, what would it look like?
This is an example of a web browser built in Python and QT. The qtweb engine widgets system introduced in qt5.6 is used. It provides a single window browsing with common controls, as well as the function of saving and loading HTML experience.
2. Web browser (TAB)
Mozzarella ashbadger: upgrade your browsing experience with tabs
Mozarella ashpacker is the latest revolution in web browsing! Back to previous page! Print! Save file! Help list! Like other browsers, it’s a coincidence.
Adding tab support makes the internal structure of the browser a lot more complex, because we now need to track the currently active browser view, not only update the UI elements (URL bar, HTTPS icon) to change the state in the currently active window, but also ensure that UI events are scheduled to the correct web view.
This is achieved by using an intermediate slot for filtering events and adding signal redirection (keeping it short using the Lamba function).
Moonsweeper: use pyqt to clone a minesweeper and fight with aliens on the moon.
Explore the mysterious moon, but don’t get too close to alien natives!
Moonsweeper is a single player puzzle game. The goal of the game is to explore the area around the space rocket you landed, not close to the deadly bug alien. A reliable counter will tell you the number of bugs (thunder) nearby.
This is a simple single player exploration game, imitating a minesweeper. You must reveal all the small squares without touching the hidden mines. This small block implementation uses customized QWidget objects, which save their states as mine, status and adjacent mine counts respectively. In this version, mines are replaced by alien bugs, which can be anything else.
First round design
In many variants of mine clearance, the initial round is considered a free round: if you hit a mine on the first click, it will be moved elsewhere. Here we are opportunistic, let’s try for the first time to ensure that it is in a non mine location. This allows us not to worry about the poor first step, which requires us to recalculate the neighbors. We interpret it as “preliminary exploration around the rocket”, which makes it sound reasonable.
No2pads: Notepad written in pyqt
A very simple Notepad clone is processed using the qtextedit widget. Support file loading, saving and printing.
Calculon: desktop calculator written in pyqt
A simple calculator application implemented in pyqt using python. The user interface is designed in QT designer, and the calculator operation is implemented using simple stack based logic.
6. Text editor
Megasolid idiom – a rich text editor written in pyqt
This editor is an extension based on Notepad. It also uses qtextedit component, but enables rich text editing.
Supports multiple fonts, styles, and paragraph text alignments. Drag and drop images are also supported, which are automatically opened and embedded.
It also supports saving and opening documents in HTML format.
Nsavier – someone is looking at you
With this camera snapshot application, you can take photos of what the camera is currently viewing. Use the qtmultimedia multimedia framework to handle all interactions with cameras and support multiple cameras, if any.
Failamp – build a simple player with pyqt
Can listen to audio and watch video, built-in playlist simple application. Use qtmultimedia and qtmultimedia widgets to handle playback and manage playlists.
The main interface provides a playlist window in which you can drag and drop media files to play. Provides standard media controls, as well as timeline widgets and volume controls.
You can also pop up a video window floating at the top.
Brown note – Desktop note application in pyqt
Use this floating notes application to take temporary notes on the desktop. Comments are stored in the local SQLite database.
This application is very simple, but demonstrates the creation of an undecorated window in pyqt. Deleting the window decoration will make it impossible to drag the window, so we must re implement this behavior ourselves.
Desktop painting application in piecasso pyqt
Use piecasso to express yourself. It’s the only painting program featuring ready-made pictures of pie.
Piecasso is a clone of the drawing program in Windows 95, on which some additions and deletions have been made. This program is characterized by standard tools, including pens, brushes, padding, spray cans, erasers, text and some shapes.
You can copy images of any shape, but paste + float is not supported. The size of the canvas is fixed, and the loaded image will be adjusted as needed. It also includes a stamp tool with pre installed pictures of delicious pie.
All tools are implemented with nested event handlers that forward events as needed. This allows a large amount of code to be reused between tools with common behavior, such as shape drawing. Adding selection area animation requires a timer (updating crawling ants), which adds some code complexity.
From a performance perspective, this is the trickiest part of the application. It is too slow to check pixels directly (the filling time of the whole canvas is about 10 seconds). Most of the code that implements this in Python uses numpy, but I don’t want to introduce dependencies for this alone.
By exporting the image as bytestring and then sampling down to one Boolean byte per pixel (for match / mismatch) to simplify the comparison cycle, a reasonable speed can be achieved.
Although this search filling algorithm is still quite stupid.
7pez – best / worst decompression application ever
Unzip your file with a cat. Drag and drop the zip file onto the hanging cat and fill its arms. Pressing the header will unzip your files to the current directory.
When you open the application, the cat’s arm is empty.
Simply drag and drop the. Zip file onto the cat to fill it with the file.
Press the cat’s head and the file will be unzipped.
Translatarrr – instant translation from any language to pirate language
From any language translation (Google translation support) to pirate language. It calls the remote APIhttp://api.funteransations.comTranslate English into pirate language, and Google’s unofficial Python wrapper translates other languages into English.
The to English section uses the python Library Based on the web interface instead of the official API client, because it is not necessary and the client is not free. So this part of the application is not guaranteed to work 100%.
The to pirate section uses a severely restricted public API. You can only translate for free 5 times, which is limited. You can pay for an API key to lift the restrictions.
So to sum up, this program is of little use.
Raindar pyqt built in weather forecast application
Get daily weather and 15 hour forecast. The data comes from the free weather forecast APIhttps://openweathermap.org/
14. Currency converter
Doughnut – an exchange rate tracker implemented with pyqt
This is a simple currency exchange rate tracker implemented with pyqt. The data comes fromfixer.ioAPI。 The default setting displays currency data for the first 180 days.
It will gradually load data and improve the resolution. The exchange rate for a given date is displayed in the right panel and updated according to the mouse position.
This screen displays the rate tracking chart for the past 180 days (using pyqtgraph). Since we do not want to send spam to the free service, the request rate to the API is limited to 1 time per second, so the complete data loading time is 180 seconds (3 minutes).
To avoid every wait, we use requests_ Cache method, which uses the local SQLite database to store the results of recent requests. A progressive “search” method is used for data requests: if there is a gap in the data, the intermediate point is filled first, and it prefers to load the nearest point in time first. This means that over time, the resolution of the whole plot will gradually improve, rather than just after the gap.
By default, the application retrieves the euro exchange rate and displays the conversion to the base currency. If you change the base currency, it will retrieve all data for the new currency again. This behavior is a little stupid, because if we have the exchange rate against the euro, we can calculate any other currency through the euro – > currency conversion (loss of a little accuracy).
Card games in ronery pyqt
Classic card game. Games are the same as cards in other aspects, providing the same options. It is built by pyqt and uses qgraphicsscene to process the game area.
The classic card winning screen is also implemented, although the playing canvas is not “filled” because it is not a bitmap. But it is still satisfactory enough.
The configuration option allows one or three at a time, and 3, 5 or unlimited rounds.
The method used here is to treat each place where cards can be placed as a “stack” object to deal with the cards it currently holds. Each stack is responsible for the layout of cards on its stack.
The stack is also responsible for accepting / rejecting attempts to place cards on it. Some stacks, such as the trading heap, do not accept any drop. Other special heaps have specific rules.
In most cases, there is no connection between any cards on the pile except the “playing” pile at the bottom. The cards at the bottom have a parent-child relationship, allowing you to drag multiple cards at a time.
The final end animation is independent and occurs outside the game time, so the first idea is to have a separate false event loop, which is checked with QApplication. ProcessEvents. But it’s a little disgusting to achieve.
On the contrary, the animation is processed by qtimer. Qtimer is usually in an idle state during playback. Once triggered, it will repeatedly ping an animation forward. This moves the cards (pretending to be “gravity”, bouncing) and re stacks them after they leave the game area. Using normal stacking code, you can re stack so that they can pile up. The last problem is to prevent user interaction, otherwise the card can still be grabbed and discarded. The easiest way to do this is to place an object on the entire window that is set to capture (and discard) all mouse clicks.
Finally, do you want to create your own application?
If you think these apps are too concise, for more information about pyqt, please refer toPyqt5 tutorial, it covers all the knowledge required to build apps using pyqt from front to back.
You can also find comments on these “small apps” on this website.
If you want to know more, you can move here to see more official examples:https://diagrams.mingrammer.c…
Open source outpostShare popular, interesting and practical open source projects on a daily basis. Participate in maintaining the open source technology resource library of 100000 + star, including python, Java, C / C + +, go, JS, CSS, node.js, PHP,. Net, etc.