PyQt5 window

If you do not have PyQT5 installed, you should install it first.
In a terminal you can type:

sudo apt-get install python3-pyqt5

If you are on a Windows or Mac computer, you can download PyQT5 from: https://www.riverbankcomputing.com/software/pyqt/download5

Related courses:

PyQt5 window

You can create a PyQT5 window using the code below:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon

class App(QWidget):

def __init__(self):
self.title = 'PyQt5 simple window - pythonspot.com'
self.left = 10
self.top = 10
self.width = 640
self.height = 480

def initUI(self):
self.setGeometry(self.left, self.top, self.width, self.height)

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()

We set the window size using the setGeometry(left,top,width,height) method. The window title is set using setWindowTitle(title). Finally show() is called to display the window.

Run with:

python3 window.py


Download PyQT5 Code

The output should look similar to the screenshot above (depending on your operating system).


One thought on “PyQt5 window

  1. Vijaya Bhaskar
    - March 11, 2018

    Nice..It works very well.

Leave a Reply

Login disabled