
- PyQt Tutorial
- PyQt - Home
- PyQt - Introduction
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Signals and Slots
- PyQt - Layout Management
- PyQt - Basic Widgets
- PyQt - QDialog Class
- PyQt - QMessageBox
- PyQt - Multiple Document Interface
- PyQt - Drag and Drop
- PyQt - Database Handling
- PyQt - Drawing API
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PyQt - Hello World
Creating a simple GUI application using PyQt involves the following steps −
Import QtGui module.
Create an application object.
A QWidget object creates top level window. Add QLabel object in it.
Set the caption of label as “hello world”.
Define the size and position of window by setGeometry() method.
Enter the mainloop of application by app.exec_() method.
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()
The above code produces the following output −

Advertisements