Tkinter Label widget is used to display text or images inside a Tkinter window. It is commonly used to show titles, captions or information in GUI applications.
Example: In this example, a simple window is created and display a basic text label.
tk.Label(root, text="Hello World") creates a label with the text Hello World.
lbl.pack() displays the label in the window.
root.mainloop() runs the GUI loop to show the window.
Syntax
Label(master, options)
Parameters:
master: The parent window or widget in which the frame is placed.
options: A set of configuration options written as key-value pairs.
Tkinter Label Options
Some commonly used options of the Label widget are:
text: The text displayed on the label.
image: Displays an image on the label.
bg: Sets the background color.
fg: Sets the text color.
font: Specifies the font style and size.
width: Sets the width of the label.
height: Sets the height of the label.
padx: Adds horizontal padding.
pady: Adds vertical padding.
relief: Sets the border style (FLAT, RAISED, SUNKEN, etc.).
Example
In this example, a Tkinter window is created and display a styled label with custom font, colors, size and border. This shows how labels are used in real GUI applications.