Python Tkinter Label

In this tutorial, we will learn about the Python Tkinter Label. Tkinter Label is used to provide a caption to widgets in Python application. Tkinter Label can be used to display normal text and images.

Syntax of Python Tkinter Label:

w = Label (master, options)  
  • master: This represents the parent window.
  • optionsHere is the list of most commonly used options for this widget.

Example of Python Tkinter Label:

from tkinter import *  
  
top = Tk()  
  
top.geometry("400x200")  
username = Label(top, text = "UserName").place(x = 30,y = 50)  
  
password = Label(top, text = "Password").place(x = 30, y = 90)  
  
sbmitbtn = Button(top, text = "Login",activebackground = "skyblue", activeforeground = "white").place(x = 30, y = 130)  
  
usernameE = Entry(top).place(x = 100, y = 50)   
  
passwordE = Entry(top).place(x = 100, y = 90)   
  
top.mainloop()

Output:

Python Tkinter Entry

Various possible options in Python Tkinter Label:

OptionDescription
anchorThis option helps us to set position of text inside the widget. By default value of anchor is CENTER.
bgThis option helps us to set normal background color of widget.
bitmapThis option helps us to display an image using label. You just have to set this option equal to an image object.
bdThis option helps us to set the border size around widget.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
fontThis option helps us to set the style of font.
fgThis option helps us to set normal foreground colour of widget.
heightThis option helps us to set height of widget.
justifyThis helps us to automatically organize the text in multiple lines.
padxThis option helps us to set space left and right of widget.
padyThis option helps us to set space above and below of widget.
reliefThis helps us to set the style of the border by which is default Flat.
textThis option helps us to set string source for label.
underlineThis option helps us to underline specified letter of the text.
widthThis helps us to set the width of the widget.
Spread the love