{"id":39,"date":"2024-03-31T15:10:44","date_gmt":"2024-03-31T14:10:44","guid":{"rendered":"http:\/\/lerking.servehttp.com\/?p=39"},"modified":"2024-04-02T14:44:51","modified_gmt":"2024-04-02T13:44:51","slug":"desktop-application-using-pyqt6","status":"publish","type":"post","link":"https:\/\/blog.lerk.ing\/index.php\/2024\/03\/31\/desktop-application-using-pyqt6\/","title":{"rendered":"Desktop application using pyqt6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\" id=\"block-ed9aa209-71d9-4856-a98d-13c66b4180da\">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 <a href=\"https:\/\/www.jan-blog.mj-lerking.dk\/index.php\/2023\/08\/28\/setting-up-a-python-virtual-environment-in-linux\/\">post<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-48306333-d8d8-4ba5-98e3-d1470f40995f\">Going forward I assume running python 3.11 in a venv. So in the virtual enviroment, install the pyqt6 module.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-aec0f102-18fa-43c7-b801-677d6df1c06d\"><strong>(p3.11)someone@somewhere:~\/venv\/p3.11$ python -m pip install pyqt6<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-2b045657-0464-4e22-8cfb-cfdcfa5716e3\">Now we create a folder for our application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-3d03ea54-c44b-48d2-9f44-b05383253334\"><strong>(p3.11)someone@somewhere:~\/venv\/p3.11$ mkdir pyqt6_application<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-7730bc02-78f5-4a47-ad1b-12308e0775d3\">Enter the folder created above.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-684ae8c8-bd7c-4068-b77a-482e9d373a79\"><strong>(p3.11)someone@somewhere:~\/venv\/p3.11$ cd pyqt6_application<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-5c5e1386-88a2-44fc-be6a-2492146e8060\">Create an empty file, called app.py<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-59700c0f-851e-4da7-88de-c758c988176b\"><strong>(p3.11)someone@somewhere:~\/venv\/p3.11$ touch app.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-1b4fdbf7-2b04-46df-81d0-af2138bf3488\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-9f822354-831a-4ae1-8803-4c564ce2ef03\">Run the app.py file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-45158fc9-d8ac-4194-b5cf-976ae4f86207\"><strong>(p3.11)someone@somewhere:~\/venv\/p3.11\/pyqt6_application$ python app.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-8275ec95-ea00-446e-ba4d-a37d532ac80f\">The resulting application looks like this, on linux.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"block-243ab2fe-67d5-4e20-882b-9fc845d37279\"><img decoding=\"async\" src=\"https:\/\/www.jan-blog.mj-lerking.dk\/wp-content\/uploads\/2023\/10\/pyqt6_app.png\" alt=\"This image has an empty alt attribute; its file name is pyqt6_app.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-80fef3f0-9c94-4557-aa29-60e4c8cd66bf\">This concludes the first post in a series of pyqt6 posts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-3772a036-8f97-43c0-9600-8ba1a22df460\">Until next time - Happy coding<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ufeffOpen document settingsOpen publish panel<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Post<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To start with, it&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[21,20,16],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-programming","tag-gui","tag-pyqt6","tag-python"],"_links":{"self":[{"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":1,"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":40,"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions\/40"}],"wp:attachment":[{"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lerk.ing\/index.php\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}