Hello World Program

Other topics

Remarks:

Creating a simple GUI application using PyQt involves the following steps −

  1. Import QtGui module

  2. Create an application object.

  3. A QWidget object creates top level window. Add QLabel object in it.

  4. Set the caption of label as “hello world”.

  5. Define the size and position of window by setGeometry() method.

  6. Enter the mainloop of application by app.exec_() method.

Hello World Program

import sys
from PyQt4 import QtGui

def window():
   app = QtGui.QApplication(sys.argv)
   w = QtGui.QWidget()
   b = QtGui.QLabel(w)
   b.setText("Hello World!")
   w.setGeometry(100,100,200,50)
   b.move(50,20)
   w.setWindowTitle("PyQt")
   w.show()
   sys.exit(app.exec_())
    
if __name__ == '__main__':
   window()

Contributors

Topic Id: 9247

Example Ids: 28688

This site is not affiliated with any of the contributors.