EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Tkinter Tutorial Python Tkinter Label
 

Python Tkinter Label

Priya Pedamkar
Article byPriya Pedamkar

Updated March 27, 2023

Python Tkinter Label

 

 

Definition of Python Tkinter Label

A Python Tkinter Label is a Tkinter widget class that is used to display text or image in the parent widget. It is a non-interactive widget whose sole purpose is to display any message to the user. Now let us first look at the Python Tkinter Label’s syntax, and then we will discuss why we use it in the first place.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

w = Label (master, option, ...)

The following are the parameters of Python Tkinter Label:

  • Master: This is the parent widget.
  • Options: This represents a list of options that can be used on the parent widget. These are key-value pairs that are separated by a comma.

Options Used in Python Tkinter Label

Python Tkinter Label is used to specify the container box where we place text or images. It is used to provide the user with information about the widgets used in the Python application.

The following are the options that can be used in the Python Tkinter Label:

  1. anchor: This option helps us control the position of the text when the parent widget has more space than the text needs. The value of the anchor corresponds to the different options available in a compass. The default option being CENTER.
  2. bg: This signifies the background color that is to be displayed behind the label and the indicator.
  3. bitmap: This is used to display an image in the label
  4. bd: This indicates the size of the border around the indicator. The default value is 2 pixels.
  5. cursor: This is used to denote the type of cursor, i.e. arrow or dot.
  6. font: This signifies the font in which the label is to be displayed.
  7. fg: This option helps to set the color of the text when we are displaying text in the label. When we are displaying bitmap, this option helps us to determine the color of the 1-bits in the bitmap.
  8. height: It determines the vertical dimension of the label.
  9. image: It helps us to set an image in the label widget.
  10. justify: It determines how multiple lines of text would be aligned with respect to each other. The possible options are LEFT for left-justified, CENTER for center alignment and RIGHT for right-justified. The default value is CENTER
  11. padx: This signifies the extra spaces added to the label’s start and end. The default value is 1.
  12. pady: This signifies the extra spaces added to the top and bottom of the text in the label. The default value is 1.
  13. relief: It determines the appearance of the border around the label. The default value is FLAT.
  14. text: This option is used to display one or more lines of text in a label widget.
  15. textvariable: This option also helps us display text in the label widget; the only difference is the method by which we are showing the text. In the textvariable method, a StringVar class object is created and then using the set option on that object, we can assign the text.
  16. underline: With this option’s help, we can display underline beneath the text in a label. The underline would start from the 0th element and commence on an nth element. The default value for underline is -1, which means there is no underline.
  17. width: This signifies the width of the label in characters. The label will be sized to fit its content if this option is not set.
  18. wraplength: This helps us to limit the number of characters in each line by mentioning the value to the desired value. The default value is 0.

Examples of Python Tkinter Label

The Label widget is a standard Tkinter widget used to display text or images. Below given are the examples of python tkinter label:

Example #1

Code:

from tkinter import *
root = Tk()
var = StringVar()
label = Label( root, anchor = CENTER , bg = "blue", textvariable = var, bd = 10, cursor = "dot")
var.set("This example is about the anchor option of Python Tkinter Label")
label.pack()
root.mainloop()

Output:

Python Tkinter Label-1.1

Example #2

Code:

from tkinter import *
root = Tk()
label = Label( root, height = 10, width = 100, padx = 2, pady = 2, text="This example is about the anchor option of Python Tkinter Label")
label.pack()
root.mainloop()

Output:

Python Tkinter Label-1.2

Example #3

Code:

from tkinter import *
root = Tk()
var = StringVar()
label = Label( root, underline = 2, wraplength = 70, textvariable = var, relief = "groove")
var.set("This example is about the anchor option of Python Tkinter Label")
label.pack()
root.mainloop()

Output:

Example-1.3

Example #4

Code:

from tkinter import *
root = Tk()
var = StringVar()
label = Label( root, font = "bold", fg = "green", bg = "yellow", textvariable = var, relief = "groove")
var.set("This example is about the anchor option of Python Tkinter Label")
label.pack()
root.mainloop()

Output:

Example-1.4

Conclusion

In the following article, we have discussed the basics of the Python Tkinter Label. Primarily we saw the syntax along with the reason why we use the Python Tkinter label. After that, we discussed the options that can be used to tweak the labels. Lastly, we concluded the article by seeing multiple examples of the same. So next time you ponder upon Tkinter, do remember to use the features of Python Tkinter Label.

Recommended Articles

This is a guide to Python Tkinter Label. Here we discuss the definition and various options used in the python Tkinter label along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Tkinter Frame
  2. Python Tkinter Canvas
  3. Python if main
  4. Python Tkinter Button

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW