Tk – Basic Widgets

  • Post author:
  • Post category:Tk
  • Post comments:0 Comments
Tk - Basic Widgets

Basic are common widgets available in almost all Tk applications. The list of available basic widgets is given below in Tcl basic widgets −

Sr.No.Widgets & Description
1LabelWidget for displaying single line of text.
2ButtonWidget that is clickable and triggers an action.
3EntryWidget used to accept a single line of text as input.
4MessageWidget for displaying multiple lines of text.
5TextWidget for displaying and optionally edit multiple lines of text.
6ToplevelWidget used to create a frame that is a new top level window.

A simple Tk example is shown below using basic widgets −

#!/usr/bin/wish

grid [label .myLabel -text "Label Widget" -textvariable labelText] 
grid [text .myText -width 20 -height 5]
.myText insert 1.0 "Text\nWidget\n"
grid [entry .myEntry -text "Entry Widget"]
grid [message .myMessage -background red -foreground white -text "Message\nWidget"]
grid [button .myButton1  -text "Button" -command "set labelText clicked"]

When we run the above program, we will get the following output −

Next Topic : Click Here

Leave a Reply