15 open source examples take you to do small desktop applications with pyqt

Time:2021-9-18

[introduction]: do you want to make your own desktop application? Here are 15 examples to get you started.

brief introduction

This time, we will introduce a collection of 15 small desktop applications written in pyqt framework and python.

Many of these applications are inLearnpyqt websiteThere is a more detailed discussion on. If you are not familiar with creating GUI applications, you can viewPyqt5 Getting Started tutorial

The address of this open source project is:https://github.com/learnpyqt/…

App list

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.

  1. Web browser(no tab) – “mooseache”
  2. Web browser(TAB) – “mozzarella ashpacker”
  3. mine clearance-“Moonsweeper”
  4. Notepad-“No2Pads”
  5. Calculator-“Calculon”(QtDesigner)
  6. text editor-“Megasolid Idiom”
  7. Camera / snapshot-“NSAViewer”
  8. player-“Failamp”
  9. Notes-“Brown Note”(QtDesigner)
  10. Drawing-“Piecasso”(QtDesigner)
  11. decompression -“7Pez”(QtDesigner)
  12. translate-“Translataarrr”(QtDesigner)
  13. weather-“Raindar”(QtDesigner)
  14. Currency converter-“Doughnut”(PyQtGraph)
  15. Solitaire-“Ronery”(qgraphicscene)

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:

Shell code

pip3 install -r requirements.txt

After installation, you can use Python 3 to execute

python3 <filename>.py

The application window appears.

Detailed introduction

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.

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

code annotation

tab

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).

3. Minesweeping

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.

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

code annotation

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.

4. Notepad

No2pads: Notepad written in pyqt

A very simple Notepad clone is processed using the qtextedit widget. Support file loading, saving and printing.

15 open source examples take you to do small desktop applications with pyqt

5. Calculator

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.

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

7. Camera

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.

15 open source examples take you to do small desktop applications with pyqt

8. Player

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.

15 open source examples take you to do small desktop applications with pyqt

You can also pop up a video window floating at the top.

15 open source examples take you to do small desktop applications with pyqt

9. Notes

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.

15 open source examples take you to do small desktop applications with pyqt

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.

10. Drawing

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.

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

code annotation

event processing

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.

Dyeing method

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.

11. Decompress

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.

15 open source examples take you to do small desktop applications with pyqt

Simply drag and drop the. Zip file onto the cat to fill it with the file.

15 open source examples take you to do small desktop applications with pyqt

Press the cat’s head and the file will be unzipped.

12. Translate

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.

15 open source examples take you to do small desktop applications with pyqt

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%.

15 open source examples take you to do small desktop applications with pyqt

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.

13. Weather

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/

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

code annotation

data processing

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.

transformation

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).

15. Solitaire

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.

15 open source examples take you to do small desktop applications with pyqt

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.

15 open source examples take you to do small desktop applications with pyqt

The configuration option allows one or three at a time, and 3, 5 or unlimited rounds.

code annotation

Card processing

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.

End animation

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.

extend

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.