Open In App

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

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.

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):
        super().__init__()
  
        # set the title
        self.setWindowTitle("Label")
  
        # 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
        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-resize-label-label.resize



Similar Reads

Change the label size and tick label size of colorbar using Matplotlib in Python
In this article, we will learn how to change the label size and tick label size of colorbar in Matplotlib using Python. Labels are a kind of assigning name that can be applied to any node in the graph. They are a name only and so labels are either present or absent. To properly label a graph, helps to identify the x-axis and y-axis. Each tick mark
2 min read
PyQt5 – How to auto resize Label | adjustSize QLabel
During the designing of the GUI (Graphical User Interface) application there is a need to display plain text as information where label is used, but sometimes information text could be large or much smaller and it is difficult to use resize() method so have to auto adjust the size of the label according to the text, in order to do so adjustSize() m
2 min read
PyQt5 – How to change font and size of Label text ?
A label is a graphical control element which displays text on a form. A label is generally used to identify a nearby text box or other widget. Some labels can respond to events such as mouse clicks, allowing the text of the label to be copied, but this is not standard user-interface practice. In this article, we will see how to change the font and
2 min read
PyQt5 – How to hide label | label.setHidden method
In this article, we will see how we can hide the Label in the PyQt5 application. A label is a graphical control element which displays text on a form. It is usually a static control; having no interactivity. A label is generally used to identify a nearby text box or another widget. In order to hide the label we use setHidden() method, this method a
2 min read
PyQt5 Scrollable Label - Setting tool tip to the label part
In this article we will see how we can set tool tip to the label part of scroll label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tool tip to the class object tool tip is set to the whole widget i.e label and the scroll bar as well. In order to add tool tip the label par
3 min read
PyQt5 Scrollable Label - Getting tool tip text of the label part
In this article we will see how we can get tool tip text of the label part of scrollable label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tool tip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to add tool tip the l
3 min read
PyQt5 Scrollable Label – Setting tool tip duration to label part
In this article we will see how we can set tooltip duration to the label part of scroll label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tooltip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to add tooltip and its
3 min read
PyQt5 Scrollable Label – Getting tool tip duration of the label part
In this article we will see how we can get the tooltip duration of the label part of scrollable label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tooltip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to get tooltip
3 min read
PyQt5 Label – Checking if label is window type
In this article we will see how we can check if the label is window type. Window type is the property which tells if the object is window type or not. In order to do this we use isWindowType method Syntax : label.isWindowType() Argument : It takes no argument Return : It returns bool Below is the implementation # importing libraries from PyQt5.QtWi
2 min read
PyQt5 Label – Checking if label is widget type
In this article we will see how we can check if the label is widget type. Widget type is the property which tells if the object is widget or not. In order to do this we use isWidgetType method Syntax : label.isWidgetType() Argument : It takes no argument Return : It returns bool Below is the implementation # importing libraries from PyQt5.QtWidgets
2 min read
Article Tags :
Practice Tags :