Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PyQt5 – How to change size of the Label | label.resize method

  • Difficulty Level : Basic
  • Last Updated : 26 Mar, 2020

While designing any GUI(Graphical User Interface) application we create labels that provide information, but sometimes there might be a case when the label size is not appropriate for the content then need of resizing of label arises.

In this tutorial, we will see how to change the size of the label in PyQt5. For this we will use resize() method.

 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

Syntax : label.resize(width, height)

Argument : It takes two integers as the argument which are :
1. Width to be set.
2. Height to be set.

Code :

# importing the required libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore
from PyQt5.QtGui import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
        # creating a label widget
        self.label_1 = QLabel('Normal Label', self)
        # moving position
        self.label_1.move(100, 100)
        # setting up border
        self.label_1.setStyleSheet("border: 1px solid black;")
        # creating a label widget
        self.label_2 = QLabel('====== extra width label =====', self)
        # moving position
        self.label_2.move(100, 150)
        # setting up border
        self.label_2.setStyleSheet("border: 1px solid black;")
        # resizing the widget
        self.label_2.resize(200, 20)
        # creating a label widget
        self.label_3 = QLabel('tiny label', self)
        # moving position
        self.label_3.move(100, 200)
        # setting up border
        self.label_3.setStyleSheet("border: 1px solid black;")
        # resizing the widget
        self.label_3.resize(60, 15)
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!