English 中文(简体)
Tk - Basic Widgets
  • 时间:2024-12-22

Tk - Basic Widgets


Previous Page Next Page  

Basic widgets are common widgets available in almost all Tk apppcations. The pst of available basic widgets is given below −

Sr.No. Widgets & Description
1 Label

Widget for displaying single pne of text.

2 Button

Widget that is cpckable and triggers an action.

3 Entry

Widget used to accept a single pne of text as input.

4 Message

Widget for displaying multiple pnes of text.

5 Text

Widget for displaying and optionally edit multiple pnes of text.

6 Toplevel

Widget 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
Widget
"
grid [entry .myEntry -text "Entry Widget"]
grid [message .myMessage -background red -foreground white -text "Message
Widget"]
grid [button .myButton1  -text "Button" -command "set labelText cpcked"]

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

Basic Widgets Example Advertisements