Setting up IDE and creating a cross platform Qt Python GUI application. This is meant to be a comprehensive guide on how to get started coding a cross platform GUI application using python. For achieving this we will use Eclipse with the plug- in Py. Dev and Py. QT which is python bindings for the cross platform UI framework QT. My aim is to make this guide as thorough as possible so if you already know some of the following parts please just skip them. If anything is missing or you find something unclear please leave a comment and I will correct it. The outline of we are going to do is: Download and install Python. Strona firmy Dell jest specjalna. Pod koniec pa. I installed python 2.7.3 in my box running windows 7 32 bits. Everything was fine until I wanted to print from my program, Then I got : “ImportError. I've been trying to add the Python path to the command line on Windows 7, yet no matter the method I try, nothing seems to work. I've used the set command, I've tried. Wireshark was initially developed by Gerald Combs. Ongoing development and maintenance of Wireshark is handled by the Wireshark core developers, a loose group of. Download and install Py. Qt. Download and install Eclipse. Download and install Pydev. Getting code completion for Py. QT in Eclipse. Creating files and coding a tiny Py. QT GUIDownload and install Python. First you need python installed on your computer. I suggest you download Python 2. For Windows users, use the windows installer suitable for your system. They will suggest you install Python in c: \python. I have done so aswell. Usually I don’t like cluttering my c: \ with catalogs but for this I make an exception. After install is done it is nice to make python available in the command prompt regardless of the catalog you are using. Do this by adding “; c: \python. You find your environment variables by right clicking on “My computer”, select properties and go to advanced settings. You should now be able to go to your command prompt and type python to start python. This is used when you are installing new libraries and trying out python commands. Download and install Py. Qt. 4Py. Qt is a set of Python bindings for Qt. It is needed to make Qt classes available in Python. For more info on Py. Qt check out the What is Py. Qt section at Riverbank Computing. Update – Install SIPAs Will Stich (thanks again Will!) commented below you first need to download and install SIP to get Py. Qt to work . Do this by downloading SIP from the Riverbanks Computing download page. In this tutorial we will use sip- 4. Extract the contents of the zip where ever you please. I will put it in c: \sip- 4. When that is done you can open the command prompt (run- > cmd) and go to your SIP folder (c: \sip- 4. Type “c: \python. SIP will be configured. Installing Py. Qt is pretty straight forward. Go to the Py. Qt. This is meant to be a comprehensive guide on how to get started coding a cross platform GUI application using python. For achieving this we will use Eclipse with the. Py. Qt version that corresponds to your python version you are using. In this example we use Py. Qt- Py. 2. 6- gpl- 4. The windows installer will installer should do all the work for you so if you installed Python in C: \Python. When done your Py. Qt. 4 installation should be saved in C: \Python. Lib\site- packages\Py. Qt. 4. Download and install Eclipse. Eclipse installation is pretty straight forward. I chose Eclipse IDE for Java developers but I think any version works fine for our purpose. Unpack into program files or where you wherever. Heck you could probably put it on a USB stick if you want to. Download and install Pydev. Pydev is a great plugin for Eclipse that allows python syntax highlighting and code completion. It can be installed in two ways; either you download and unpack the files into the plug- in folder in your Eclipse directory or you use the installation manager in Eclipse. I suggest you use the installation manager! So, start eclipse, choose a workspace you want to use and go to “Help - > Install new software. Follow the steps in the installation guide. You might get a bunch of dialog boxes warning you about stuff, I just pressed yes all the way and it worked fine. The Eclipse intallation manager, installing Py. Dev. When that is done we can create our first Python project with Pydev. Your “File - > New” menu should look like the image below. Select “Pydev Project”. A new dialog box will open. Write the name of your project in the “Project name: ” field. If this is the first time you create a Python project you will need to configure your Python interpreter. Do so by clicking on the “Click here to configure an interpreter not listed” link. A new dialog box will open that looks like the one in the image below. Before finding the Python interpreter. Press the “Auto Config” box and Pydev will (hopefully) find your installed python interpreter. The auto config dialog findings should open in a new dialog that looks like the one below. Select the ones selected in the figure below and click “OK”. Auto finding the Python Interpreter. Now this might be over pedagogical but your Python Interpreters box should look like the figure below. Press OK we are done with the interpreters! The Python Interpreters found. Now press “Finish” to create your Pydev project. Eclipse and Pydev will create a src folder and show the referenced Python interpreter. Getting code completion for Py. QT in Eclipse. Not having code completion while learning something new or using a new library is a pain so lets try to avoid that! To get code completion for your Py. QT library we need to add it to the external libraries included in the project. Go to the menu Project - > Properties - > Py. Dev PYTHONPATH - > External Libraries - > Add source folder. Add the path where you have installed your Py. QT files. They are most likely, if you used the windows installer, locaded in C: \Python. Lib\site- packages\Py. Qt. 4. If all is well you should have something that looks like the figure below. Setting up the Py. QT in external libraries. Creating files and coding a tiny Py. QT GUINow we are done with the development environment things! Lets try if this thing works! First thing we need to do is to add a main module. Do this by right clicking on your src- folder select new - > Pydev Module. In the “Name” field enter “Main” and in the template. You could name the file anything you like, it will work either way, but it is in my opinion always nice to have a startup file called Main. It should look like the image below. Creating a new Py. Dev Project. This will create a new main module for you with the code below. Created on 2 apr 2. Mikael Hal. If you would to start a bigger project you would probably want to create a new file for your user interface. Anyway, we want to create a QT GUI so lets start doing that! I’m going to describe this process by first showing you the end result and then I’m going to describe what the different rows do afterwords. Here is what we will end up with: The tiny Py. QT GUI running in Windows. And this is the code you need to get it working. Py. Qt. 4 import Qt. Gui. class Hello. Python(Qt. Gui. QWidget). Lets start from the top! This imports the Qt libraries needed for this little application. We only needed the Qt. Gui so that is what we imported. This line creates the class called Hello. Python and says that it should inherit from Qt. Widget which is the base Qt class for all user interface objects. These two rows will make this class have no parent and thus making it the main class. First one Label is instantiated for displaying text and then one Line. Edit for entering text in. Then a Grid. Layout is set up where we put the Label and Line. Edit. Lastly we set the layout in on the QWidget and set the window title. The sys. argv are command line arguments passed on to the application. On exit() the loop ends and sys. Conclusion. With this guide I hope you can easily get started programming GUI applications in Python. Again, if you find that something is unclear, missing or plain wrong please leave a comment or contact us in some other way and we will fix it. I will continue posting solutions I use for the problems I encounter while developing in QT so please subscribe to our RSS feed or follow us on twitter. If you want to read more visit the learning python blog or read zetcode’s python tutorials. You should also visit the Py. QT class reference library at www. Updates. 5 May 2. There is a great set of tutorials (and a link to this post) that you can use for further learning at the diotavelli Py.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2017
Categories |