DEV Community

Cover image for PyQt: cross-platform GUI programming
jones268
jones268

Posted on

5 1

PyQt: cross-platform GUI programming

PyQt is a set of Python bindings for The Qt Toolkit library. The Qt toolkit is a C++ framework that is primarily used for creating graphical user interfaces (GUIs). It supports different platforms, such as Microsoft Windows, Mac OS and Linux.

The Python programming language provides an ideal and easy to learn scripting language for developing graphical user interfaces with PyQt. The bindings provide a high level interface between Python and Qt.

PyQt allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is also suitable for applications requiring "quick-and-dirty" GUI prototyping.

PyQt Hello World

"Hello World" is a typical example program for demonstration purposes.

This is a basic "hello world" application using the PyQt toolkit. It should give you an idea of what the PyQt framework is like.

# load pyqt widgets
from PyQt5.QtWidgets import * 
import sys

class Window(QMainWindow):
    def __init__(self):
        super().__init__()

        # the window title
        self.setWindowTitle("hello dev!")

        # window size
        self.setGeometry(0, 0, 200, 200)

        # create label 
        self.label = QLabel("Hello World", self)

        # show all the widgets
        self.show()

# create the app
App = QApplication(sys.argv)

# create Window
window = Window()

# start
sys.exit(App.exec())
Enter fullscreen mode Exit fullscreen mode

To run the application, just type "python hello.py". This will open a window with the "Hello World" text.

hello world in python pyqt

The window properties are set in the class

# the window title
self.setWindowTitle("hello dev!")

# window size
self.setGeometry(0, 0, 200, 200)
Enter fullscreen mode Exit fullscreen mode

Besides labels, you can add many things to the window like buttons, tables, select boxes, checkbox, video widgets and much much more. If you are new to PyQt, I recommend this course

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay