Open In App

PyQt5 – How to change font and size of Label text ?

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

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 size of the text in Label, we can do this by using setFont() method.

Syntax : label.setFont(QFont(font_name, size))

Argument : It take two argument :
1. Font name it can be ‘Arial’, ‘Times’ etc.
2. Size to be set in integer.

Below is the Python implementation –




# importing the required libraries
  
from PyQt5.QtWidgets import * 
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
        # by default label will display at top left corner
        self.label_1 = QLabel('Arial font', self)
  
        # moving position
        self.label_1.move(100, 100)
  
        # setting font and size
        self.label_1.setFont(QFont('Arial', 10))
  
        # creating a label widget
        # by default label will display at top left corner
        self.label_2 = QLabel('Times font', self)
  
        # moving position
        self.label_2.move(100, 120)
  
        # setting font and size
        self.label_2.setFont(QFont('Times', 10))
  
  
        # 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-change-font-Qlabel



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 change size of the Label | label.resize method
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. S
2 min read
PyQt5 – Change the text font and size in Push button
In this article we will see how to change the text style or size of Push Button.QPushButton is a simple button in PyQt, when clicked by a user some associated action gets performed. For adding this button into the application, QPushButton class is used.In order to set font we will use setFont method which takes QFont object as argument. Syntax : bu
2 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
How to Change the Tkinter Label Font Size?
Tkinter Label is used to display one or more lines, it can also be used to display bitmap or images. In this article, we are going to change the font-size of the Label Widget. To create Label use following: Syntax: label = Label(parent, option, ...) Parameters: parent: Object of the widget that will display this label, generally a root object text:
5 min read
PYGLET – Accessing Label Text Font Size Property
In this article we will see how we can access the label text font size property in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set
2 min read
Python PyQt5 – How to change font and size of Status Bar Message
We can set message to a Status Bar by using showMessage() method. In this article, we will see how to change the font and the size of StatusBar message. In order to do this we will use setFont() method. Syntax : self.statusBar().setFont(QFont(font_name, font_size)) Argument : It take two argument : 1. Font name it can be ‘Arial’, ’Times’ etc. 2. Si
1 min read
PyQt5 – How to change text of pre-existing label | setText method
In GUI applications there is need of displaying information this done using labels in PyQt5, but sometimes there is also a need of changing the text of the label, in this tutorial we will see how it can be done. setText() method is used to change the content of the label. Syntax : label.setText(Info) Argument : It takes string as an argument. Code
1 min read
wxPython - Change Button Label Font
In this article we are going to learn that how can we change the font of the label text present on the button present in the frame. We need to follow some steps as follows: Step 1: Create a wx.Font object. Step 2: Add different attributes of font in parameters like: family, style etc. Step 3: Set font by using SetFont() function. Syntax: wx.Button.
1 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
Article Tags :
Practice Tags :