Easiest way to add a GUI to a Python code?

10,914

Edit: This is a very old post. If you come across now, you should look out for versions of qt5 instead of qt4. Qt5 is even more awesome.


You should go for Qt framework (What is Qt?) which offers great and well documented GUI libraries which work across multiple platforms.

For Python there is PyQt (What is PyQt?) which offers python bindings for the Qt framework.

sudo apt-get install python-qt4 pyqt4-dev-tools

To get started, here is a simple "Hello World"-tutorial:

Create a file ~/tmp/helloworld.py:

import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_()

Run it:

python ~/tmp/helloworld.py

In addition, you can use the Qt Designer IDE which is available in the ubuntu repositories and offers some nice development features for GUIs.

sudo apt-get install qt4-designer 
Share:
10,914

Related videos on Youtube

Hollis Scriber
Author by

Hollis Scriber

Updated on September 18, 2022

Comments

  • Hollis Scriber
    Hollis Scriber over 1 year

    I'm planning out a Raspberry Pi project, and I want to make it very easy to use. My dad will be using it, and I'd like for it to be usable without having to interact with the terminal. I just want a basic GUI that prompts for values to be input, processes them, and allows my program to act on them. I want the values to be repeatedly used, but easy to change when the conditions change, there's an error, etc. I thought the easiest way to do this would be a light weight Ubuntu app, but I may be wrong. Any suggestions?

    • web.learner
      web.learner about 11 years
      Is this going to run on the pi or on Ubuntu?
  • Hollis Scriber
    Hollis Scriber about 11 years
    This looks nice. Would it be able to be put into an application of sorts? Or at least an executable file to make it very point-and-clickable?
  • q9f
    q9f about 11 years
    Of course you can compile your code and create an executable for various platforms. I'm doing that with cmake and qt-creator. But that's another question. :)