
- Tcl Tutorial
- Tcl - Home
- Tcl - Overview
- Tcl - Environment Setup
- Tcl - Special Variables
- Tcl - Basic Syntax
- Tcl - Commands
- Tcl - Data Types
- Tcl - Variables
- Tcl - Operators
- Tcl - Decisions
- Tcl - Loops
- Tcl - Arrays
- Tcl - Strings
- Tcl - Lists
- Tcl - Dictionary
- Tcl - Procedures
- Tcl - Packages
- Tcl - Namespaces
- Tcl - File I/O
- Tcl - Error Handling
- Tcl - Built-in Functions
- Tcl - Regular Expressions
- Tk Tutorial
- Tk - Overview
- Tk - Environment
- Tk - Special Variables
- Tk - Widgets Overview
- Tk - Basic Widgets
- Tk - Layout Widgets
- Tk - Selection Widgets
- Tk - Canvas Widgets
- Tk - Mega Widgets
- Tk - Fonts
- Tk - Images
- Tk - Events
- Tk - Windows Manager
- Tk - Geometry Manager
- Tcl/Tk Useful Resources
- Tcl/Tk - Quick Guide
- Tcl/Tk - Useful Resources
- Tcl/Tk - Discussion
Tk - Label Widget
A label widget is a common widget used in almost all Tk applications that is used to display simple text. The syntax for label widget is shown below −
label labelName options
Options
The options available for the label widget are listed below in table −
Sr.No. | Syntax & Description |
---|---|
1 | -background color Used to set background color for widget. |
2 | -borderwidth width Used to draw with border in 3D effects. |
3 | -font fontDescriptor Used to set font for widget. |
4 | -foreground color Used to set foreground color for widget. |
5 | -height number Used to set height for widget. |
6 | -padx number Sets the padx for the widget. |
7 | -pady number Sets the pady for the widget. |
8 | -relief condition Sets the 3D relief for this widget. The condition may be raised, sunken, flat, ridge, solid, or groove. |
9 | -text text Sets the text for the widget. |
10 | -textvariable varName Variable associated with the widget. When the text of widget changes, the variable is set to text of widget. |
11 | -width number Sets the width for widget. |
12 | -justify alignment Sets the alignment of text, which can be left, center, or right. |
A simple example for label widget is shown below −
#!/usr/bin/wish grid [label .myLabel -background red -foreground white -text "Hello World" -relief ridge -borderwidth 8 -padx 10 -pady 10 -font {Helvetica -18 bold} -height 10 -width 35 -textvariable myvariable -justify left -underline 1] set myvariable "Test Hello"
When we run the above program, we will get the following output −
