There are countless of tutorials online on Python programming.
But all of them seem to be concentrating on all the logic and inner workings, and as a result you have a great application…a command line application.
The problem with that is, you are more likely to stop being interested when only creating a CLI application since it doesn’t look as professional.

So, I will be diving straight in to GUI programming.
We will learn the logic as we go along, so you end up with beautiful applications.
And, I don’t expect you to have too much experience with Python or programming in general.
If you have a logic mind, then why not try it out?

We will be using PyQt.
If you don’t know what that is, it’s the combination of Python and Qt.
Qt was developed for use with the C language family, but thanks to the hard work by some expert developers, it has been ported for use with Python.
Everything that original Qt uses, PyQt can also do, and it’s only limited to your imagination.

Please note, if you aim to create games, mobile apps, or web apps, you may want to try different projects instead.
For games, try PyGame (although Python isn’t the best language for 3D games)
For mobile apps, there is a Python solution for Android, but you may want to try Kivi instead of Qt.
And for Python as webapps, try Django, it’s an amazing rapid platform for creating webapps, designed to be deployed ultra fast (I may do a tutorial of that at some point in the future).

Installation

You will need some packages on top of Python that is already pre-installed. If you aren’t using Ubuntu or a Debian based distro, consult your package manager to install these packages, although they should be available for you.

What we are going to install are these packages:

* python-qt4 – This is PyQt
* qt4-designer – A designer application which can drag-and-drop create the application
* PyCharm – Python IDE, you can use your favourite IDE instead, but PyCharm is excellent if you don’t have a favourite (yet)
* Virtualbox and Windows – Optional: Install these if you want to deploy your apps to Windows too, but don’t have a Windows system on hand.

To install, run the following command in a terminal:

sudo apt-get install python-qt4 qt4-designer

After these are installed, we need to install PyCharm, skip this step if you are going to use a different IDE:

Go to: http://www.jetbrains.com/pycharm/download/ and download the Community Edition.

Once you have downloaded it, unpack the tar ball anywhere you want, like your Home directory.
Then go into the PyCharm directory and the ‘bin’ subdirectory. In there you will find ‘pycharm.sh’, run that and you’re ready to go.
I do recommend making a shortcut for that file so you don’t need to keep heading there just to start it. Or even better, create a .desktop file and place that in the application bar.

Once installed, if you get an error telling you that there is no Python, click on the warning and a screen will pop up, to the top right you will see a little + symbol, click on that and select Python 2.7 (default on Ubuntu) and hit Apply and Close, you are now ready.

Qt Designer

Qt Designer is a lot like Glade for anyone who ever developed in Gtk. The main difference is that Glade was extremely strict on using correct layouts.
This meant that you spent a lot of your time dividing the window into areas to place your widgets. The difference with Qt is that it’s not that strict. You can just drag and drop the different widgets wherever you want. The downside to this is that when you maximize or resize a window, the widgets just stay in place. But that’s nothing to be concerned about in the beginning.

How UIs designed in Qt Designer works is rather brilliant.
You create an applications design, and save it. This will create a .ui file. But a terminal application has been installed that will convert the ui file into a Python file. We can then make a controller Python file from where we can control all of our widgets and make the application come to life.

In the next part of the tutorial we will create a basic ‘Hello World’ application (it’s tradition). But we will ask for input and in future tutorials just build on top of it.

I hope to see you soon

Advertisements