EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Tkinter Tutorial Python Tkinter Label
Secondary Sidebar
Tkinter Tutorial
  • Tkinter
    • Python Tkinter
    • Tkinter Widgets
    • Tkinter background image
    • Tkinter button color
    • Tkinter place
    • Python Tkinter Button
    • Python Tkinter Canvas
    • Tkinter Frame
    • Tkinter LabelFrame
    • Python Tkinter Label
    • Tkinter Text
    • Tkinter Scrollbar
    • Tkinter Listbox
    • Tkinter Spinbox
    • Tkinter Checkbutton
    • Tkinter Menu
    • Tkinter Menubutton
    • Tkinter OptionMenu
    • Tkinter Messagebox
    • Tkinter Grid
    • Tkinter Pack
    • Tkinter Scale
    • Tkinter Table
    • Python Tkinter Entry
    • Tkinter after
    • Tkinter Colors
    • Tkinter Font
    • Tkinter PhotoImage
    • Tkinter TreeView
    • Tkinter Notebook
    • Tkinter Combobox
    • Tkinter Bind
    • Tkinter Icon
    • Tkinter Window Size
    • Tkinter Color Chart
    • Tkinter Slider
    • Tkinter Calculator
    • Tkinter geometry
    • Tkinter image
    • Tkinter input box
    • Tkinter mainloop

Python Tkinter Label

By Priya PedamkarPriya Pedamkar

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.

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,697 ratings)

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
Popular Course in this category
Python Certifications Training Program (40 Courses, 13+ Projects)
  40 Online Courses |  13 Hands-on Projects |  215+ Hours |  Verifiable Certificate of Completion
4.8
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more