Skip to content
Related Articles

Related Articles

PyQt5 – How to stop resizing of window | setFixedSize() method
  • Last Updated : 26 Mar, 2020

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 setFizedSize() 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 :






# 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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :