# HelloQt.py (c) Kari Laitinen # http://www.naturalprogramming.com # 2009-11-02 First program version created. # 2009-11-03 Last modification. # This program draws two lines of text onto the screen. #!/usr/bin/python import sys from PyQt4 import QtGui, QtCore # We'll derive our application window from QtGui.QWidget. # Qt documentation says that a widget without a parent widget # is always an independent window (top-level widget). class HelloWindow( QtGui.QWidget ) : def __init__(self, parent=None ) : QtGui.QWidget.__init__( self, parent ) self.setGeometry( 300, 300, 400, 250 ) self.setWindowTitle( "THIS IS A SIMPLE PyQt APPLICATION" ) def paintEvent( self, event ) : painter = QtGui.QPainter() painter.begin( self ) painter.drawText( 80, 100, "Hello. I am a PyQt Application." ) painter.drawText( 80, 150, "The coordinates of this line are (80,150)." ) painter.end() this_application = QtGui.QApplication( sys.argv ) application_window = HelloWindow() application_window.show() this_application.exec_() # NOTES: # A nice PyQt tutorial can be found at http://zetcode.com/tutorials/pyqt4/ # PyQt class reference can be found at # http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html # PyQt INSTALLATION IN WINDOWS: # First you need the basic Python installation. # Then you need a corresponding binary for PyQt from # http://www.riverbankcomputing.co.uk/software/pyqt/download # When you execute the .exe file, it installs PyQt to the # same folder in which the basic Python was installed. # After this you can run PyQt applications simply by commanding # in the following way: # \Python26\python HelloQt.py