The Wayback Machine - https://web.archive.org/web/20240912003552/https://www.geeksforgeeks.org/how-to-change-the-tkinter-label-text/
Open In App

How to change the Tkinter label text?

Last Updated : 17 Aug, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisites: Introduction to tkinter

Tkinter is a standard GUI (Graphical user interface) package for python. It provides a fast and easy way of creating a GUI application.

To create a tkinter application:

  • Importing the module — tkinter
  • Create the main window (container)
  • Add any number of widgets to the main window.
  • Apply the event Trigger on the widgets.

Widgets are the controlling tools for any GUI application. Here widget’s main role is to provide a good variety of control. Some widgets are buttons, labels, text boxes, and many more. 

One of its widgets is the label, which is responsible for implementing a display box-section for text and images. Click here For knowing more about the Tkinter label widget.

Now, let’ see how To change the text of the label:

Method 1: Using Label.config() method.

Syntax: Label.config(text)

Parameter: text– The text to display in the label. 

This method is used for performing an overwriting over label widget.

Example:

Python3




# importing everything from tkinter
from tkinter import *
 
# creating the tkinter window
Main_window = Tk()
 
# variable
my_text = "GeeksforGeeks updated !!!"
 
# function define for
# updating the my_label
# widget content
def counter():
   
    # use global variable
    global my_text
     
    # configure
    my_label.config(text = my_text)
 
# create a button widget and attached  
# with counter function  
my_button = Button(Main_window,
                   text = "Please update",
                   command = counter)
 
# create a Label widget
my_label = Label(Main_window,
                 text = "geeksforgeeks")
 
# place the widgets
# in the gui window
my_label.pack()
my_button.pack()
 
# Start the GUI
Main_window.mainloop()


 
 Output:

 

 

Method 2: Using StringVar() class.

 

Syntax: StringVar()

Return: String variable object

 This class is used for setting the values and changing it according to the requirements. 

Python3




# importing everything from tkinter
from tkinter import *
 
# create gui window
Main_window = Tk()
 
# set the configuration
# of the window
Main_window.geometry("220x100")
 
# define a function
# for setting the new text
def java():
    my_string_var.set("You must go with Java")
 
# define a function
# for setting the new text
def python():
    my_string_var.set("You must go with Python")
 
 
 
# create a Button widget and attached  
# with java function  
btn_1 = Button(Main_window,
               text = "I love Android",
               command = java)
 
# create a Button widget and attached  
# with python function
btn_2 = Button(Main_window,
               text = "I love Machine Learning",
               command = python)
 
# create a StringVar class
my_string_var = StringVar()
 
# set the text
my_string_var.set("What should I learn")
 
# create a label widget
my_label = Label(Main_window,
                 textvariable = my_string_var)
 
 
# place widgets into
# the gui window
btn_1.pack()
btn_2.pack()
my_label.pack()
 
# Start the GUI 
Main_window.mainloop()


 

 



Previous Article
Next Article

Similar Reads

How To Change The Text Color Using Tkinter.Label
In Tkinter, we can customize the styling of elements such as labels to enhance the appearance of our GUI applications. One common customization is changing the text color of a Label widget. In this article, we will explore different approaches to changing the text color using tkinter.label in Python. Change The Text Color Using Tkinter.LabelBelow a
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
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 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
Change The Color Of A Tkinter Label Programmatically
Tkinter is a module in Python which is used to create GUI applications. It has many useful widgets such as Label, Button, Radiobutton, Checkbutton, Listbox, and more. In this article, we will learn about changing the color of a Tkinter label widget in Python. Tkinter Label WidgetThe Label is one of the widgets in Tkinter. It is used to display text
4 min read
How to Get the Tkinter Label Text?
Prerequisite: Python GUI – Tkinter Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create GUI applications. Creating
2 min read
Underline Text In Tkinter Label Widget
Tkinter is a module in Python which is used to create GUI applications. It has many useful widgets such as Label, Button, Radiobutton, Checkbutton, Listbox, and more. In this article, we will learn about changing the color of a Tkinter label widget in Python. By default, the text of a Label in Tkinter is not underlined. To have an underline in a te
3 min read
How To Align Text In Tkinter Label?
Aligning text within Tkinter labels is a fundamental aspect of GUI (Graphical User Interface) design in Python. Tkinter provides various options for aligning text within labels to enhance the visual presentation of your application. In this article, we'll explore different methods to align text in Tkinter labels in Python. The Label WidgetThe Tkint
3 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
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 – 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
Change the color of certain words in the tkinter text widget
Python has various options for Graphical User Interface (GUI) development. One of the options is Tkinter. Tkinter and Python together provide a faster way for GUI development. The Tk GUI toolkit provides an object-oriented interface. For creating GUI applications using Tkinter we have to follow a few steps – Import Tkinter module.Create the main wi
3 min read
How to Set Border of Tkinter Label Widget?
The task here is to draft a python program using Tkinter module to set borders of a label widget. A Tkinter label Widget is an Area that displays text or images. We can update this text at any point in time. ApproachImport moduleCreate a windowSet a label widget with required attributes for borderPlace this widget on the window created Syntax: Labe
2 min read
Add Shadow in Tkinter Label in Python
Tkinter is the standard GUI library for Python and is included with most Python installations. It provides a number of widgets and tools for creating graphical user interfaces (GUIs) in Python. One of the most common widgets in Tkinter is the Label widget, which is used to display text and images. In this article, we will look at how to add a shado
4 min read
Python Tkinter - Label
Tkinter Label is a widget that is used to implement display boxes where you can place text or images. The text displayed by this widget can be changed by the developer at any time you want. It is also used to perform tasks such as underlining the part of the text and spanning the text across multiple lines. It is important to note that a label can
4 min read
How To Make A Label Bold Tkinter?
Tkinter has various customization settings that allow you to modify the appearance of GUI elements, including labels. Making a label bold can be achieved using different methods, such as configuring the font directly or using styles. In this article, we will explore different approaches to make a label bold in tkinter. Make A Label Bold in TkinterB
2 min read
Remove An Image In A Label In Tkinter
Tkinter is a GUI-creating module in Python that is used to create many applications. It has many useful widgets such as Label, Checkbutton, Button, Checkbox, and more. In this article, we will discuss how we can remove an image from the Label widget in Tkinter in Python. Tkinter Label WidgetThe label is one of the widgets in Tkinter. It is used to
4 min read
How to Update the Image of a Tkinter Label Widget?
Tkinter is a GUI-creating module in Python that is used to create many applications. It has many useful widgets such as Label, Checkbutton, Button, Checkbox, and more. In this article, we will discuss how we can update an image from the Label widget in Tkinter in Python. Tkinter Label WidgetThe Label is one of the widgets in Tkinter. It is used to
4 min read
Center a Label In a Frame of Fixed Size In Tkinter
Tkinter is a module in Python which is used to create GUI applications. It has many useful widgets such as Label, Button, Radiobutton, Checkbutton, Listbox, and more. In this article, we will learn about changing the color of a Tkinter label widget in Python. Label in TkinterThe Label is one of the widgets in Tkinter. It is used to display text in
3 min read
Why is this simple Tkinter UI not displaying the specified label
Creating user interfaces with Tkinter in Python is a popular choice due to its simplicity and ease of use. However, even simple Tkinter applications can sometimes have issues that prevent them from working as expected. One common problem is when a specified label does not display on the UI. This article will explore potential reasons for this issue
3 min read
How to Set Text of Tkinter Text Widget With a Button?
Prerequisite: Python GUI – tkinter Text Widget is used where a user wants to insert multi-line text fields. In this article, we are going to learn the approaches to set the text inside the text fields of the text widget with the help of a button. Approach: Using insert and delete methodImport the Tkinter module.Create a GUI window.Create our text w
2 min read
How to wrap text within Tkinter Text Box?
In this article, we will see that how can we wrap the text in the TKinter Text-Box using the Tkinter module Called textWrap Module. The textwrap module can be used for wrapping and formatting plain text. This module provides formatting of the text by adjusting the line breaks in the input paragraph. Example 1: Firstly We will import the Tkinter Lib
2 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
PyQt5 – How to change color of the label ?
While creating a Label in PyQt5, we can see that there is no background color. In this article we will see how to add background color to the Label. In order to add border to the Label we will use label.setStyleSheet() method, this will add the background color to the label, it is same like designing the CSS style sheet. Syntax : label.setStyleShee
2 min read
Article Tags :
Practice Tags :