Qt4 window
PyQt4 window on UbuntuIn this tutorial you will learn how to create a graphical hello world application with PyQT4.
PyQT4, it is one of Pythons options for graphical user interface (GUI) programming.
Related course:
Practice Python with interactive exercises
PyQt4 window example:
This application will create a graphical window that can be minimized, maximimzed and resized it.#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
import sys
from PyQt4.QtGui import *
# Create an PyQT4 application object.
a = QApplication(sys.argv)
# The QWidget widget is the base class of all user interface objects in PyQt4.
w = QWidget()
# Set window size.
w.resize(320, 240)
# Set window title
w.setWindowTitle("Hello World!")
# Show window
w.show()
sys.exit(a.exec_())
The PyQT4 module must be immported, we do that with this line:
from PyQt4.QtGui import *
We create the PyQT4 application object using QApplication():
a = QApplication(sys.argv)
We create the window (QWidget), resize, set the tittle and show it with this code:
w = QWidget()
w.resize(320, 240)
w.setWindowTitle("Hello World!")
Don't forget to show the window:
# Show window
w.show()
You can download a collection of PyQt4 examples: Download PyQT Code (Bulk Collection)