Desktop application using pyqt6

To start with, it’s recommended to do this in a virtual environment. For information on how to set this up on linux mint 21.2, see this post

Going forward I assume running python 3.11 in a venv. So in the virtual enviroment, install the pyqt6 module.

(p3.11)someone@somewhere:~/venv/p3.11$ python -m pip install pyqt6

Now we create a folder for our application.

(p3.11)someone@somewhere:~/venv/p3.11$ mkdir pyqt6_application

Enter the folder created above.

(p3.11)someone@somewhere:~/venv/p3.11$ cd pyqt6_application

Create an empty file, called app.py

(p3.11)someone@somewhere:~/venv/p3.11$ touch app.py

Now you can start using pyqt6. Start by opening the app.py file in your favorite editor. Enter/copy and paste the code below in the app.py file. Now save the file.from PyQt6.QtWidgets import QApplication, QWidget # Only needed for access to command line arguments import sys # You need one (and only one) QApplication instance per application. # Pass in sys.argv to allow command line arguments for your app. # If you know you won’t use command line arguments QApplication([]) works too. app = QApplication(sys.argv) # Create a Qt widget, which will be our window. window = QWidget() window.show() # IMPORTANT!!!!! Windows are hidden by default. # Start the event loop. app.exec() # Your application won’t reach here until you exit and the event # loop has stopped.

Run the app.py file.

(p3.11)someone@somewhere:~/venv/p3.11/pyqt6_application$ python app.py

The resulting application looks like this, on linux.

This image has an empty alt attribute; its file name is pyqt6_app.png

This concludes the first post in a series of pyqt6 posts.

Until next time – Happy coding

Open document settingsOpen publish panel

  • Post

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *