Open In App

PySide2 – How to create window?

PySide2 is one of the most famous libraries in python for building GUI applications. In this article, we will build an empty window using PySide2 Library.

Steps to create empty window :

1. Import PySide2 in your code
2. Create QApplication object
3. Create object for QWidget
4. Increase the size of the window.
4. Show window using show() function




# import system module
import sys
 
# import PySide2 modules
from PySide2.QtWidgets import QApplication, QWidget
 
# create new app
app = QApplication(sys.argv)
 
# create main window
mainwindow = QWidget()
 
# resize window to 550 * 400
mainwindow.resize(550, 400)
 
# set title to the window frame
mainwindow.setWindowTitle('GeeksForGeeks')
 
# invoke show function
mainwindow.show()
 
# to kee in loop invoke exec_() function
app.exec_()

As we execute this program, a new empty window of size 550*400 will pop up on your screen with the label ‘GeeksforGeeks’.



Output:



Article Tags :