tkinter
  1. tkinter-label

Label - Tkinter Display Widgets

Tkinter is a popular GUI programming toolkit for Python. A Label is a Tkinter widget used to display text or images. It is used to provide descriptions, captions for other widgets, or as standalone text on a GUI.

Syntax

The syntax for creating a Label in Tkinter is as follows:

widget = Label(parent, options)

Here, widget is the Label widget that will be created, parent is the parent widget of the Label, and options are the configuration options for the Label.

Example

The following example creates a Label widget and packs it into a window:

import tkinter as tk

root = tk.Tk()

label = tk.Label(root, text="Hello, World!")
label.pack()

root.mainloop()

Upon running the code, the window will display the Label with the text "Hello, World!".

Output

The Label widget displays text or images in a Tkinter window.

Explanation

The Label widget is used to display text or images in a Tkinter application. It is commonly used to provide context or labels for other widgets in the GUI. The text or image displayed in the Label can be set using the text or image option provided by the widget.

Use

The Label widget is versatile and can be used to add text or images to a Tkinter GUI. It is commonly used to provide labels or context for other widgets in the GUI. The Label widget can be configured in various ways to suit different use cases.

Important Points

  • The text option is used to display text in the Label widget.
  • The image option is used to display images in the Label widget.
  • The anchor option specifies the position of the text or image within the Label widget.
  • The font option specifies the font used for the text in the Label widget.
  • The fg option specifies the foreground color of the text in the Label widget.

Summary

In this tutorial, we learned about the Label widget in Tkinter. We saw the syntax and usage of the widget, along with an example. The Label widget is a useful widget for adding text or images to a Tkinter GUI.

Published on: