Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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



Last Updated : 05 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads