How to make a simple GUI design using PyQt5

Profile Picture

visheshnamdev72

Thursday, 2024-09-05



PyQt5 is a set of Python bindings for the Qt application framework, allowing developers to create cross-platform graphical user interfaces (GUIs) with Python. Qt is widely used for developing desktop applications due to its comprehensive set of features and modern UI components. PyQt5 enables Python developers to access these features and create fully functional desktop applications with Python.


Key Features of PyQt5:

  • Cross-Platform: Works on Windows, macOS, and Linux.
  • Comprehensive Widget Set: Offers a wide range of UI elements like buttons, menus, dialog boxes, and more.
  • Event Handling: Uses an intuitive signal and slot mechanism for managing user interactions.
  • Modern Look and Feel: Supports advanced UI features like layouts, animations, and stylesheets.
  • Integration: Can be integrated with databases, multimedia, web views, and more.
  • Custom Widgets: Allows developers to create custom widgets for specialized needs.


A Simple GUI(Graphical user Interface) Design


import sys 
from PyQt5.QtWidgets import QApplication, QLabel, QWidget 


def main():
    app  = QApplication(sys.argv)
    window = QWidget() 


    label = QLabel('Vishesh Namdev', window)
    label.move(100,580)


    window.setWindowTitle('TRC')
    window.setGeometry(500,500,500,500)
    window.show()


    sys.exit(app.exec_())
    
if __name__ == '__main__':
    main()


This PyQt5 code creates a simple GUI application:

  • Imports necessary modules.
  • QApplication: Initializes the app.
  • QWidget: Creates the main window.
  • QLabel: Adds a label with the text "Vishesh Namdev" at position (100, 580).
  • Window Setup: Sets the window title to "TRC" and its size to 500x500 pixels.
  • window.show(): Displays the window.
  • Event Loop: Runs the application until the window is closed.



Thank You

How did you feel about this post?

😍 🙂 😐 😕 😡