HomeLanguagesPyQt5 – How to stop resizing of window | setFixedSize() method

PyQt5 – How to stop resizing of window | setFixedSize() method

In this article, we will see how to stop resizing of the main window. While making a window, we get options like going full screen and using cursor to change its size. By using setFixedSize() method we can prevent the resizing of the image.

Syntax : self.setFixedSize(width, height) Argument : It takes two integer as argument i.e width and height. Action performed : It set the fixed size of window.

Code : 

Python3




# importing the required libraries
 
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
 
 
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
 
 
        # set the title
        self.setWindowTitle("Python")
 
        width = 500
        height = 400
        # setting  the fixed size of window
        self.setFixedSize(width, height)
 
        # creating a label widget
        self.label_1 = QLabel("Fixed size window", self)
 
        # moving position
        self.label_1.move(100, 100)
 
        # setting up the border
        self.label_1.setStyleSheet("border :3px solid black;")
 
        # resizing label
        self.label_1.resize(120, 80)
 
        # show all the widgets
        self.show()
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
# start the app
sys.exit(App.exec())


Output : pyqt-stop-resize-window

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS