
- 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 - Button Widget
Tk button widget is a clickable widget that triggers an action. The syntax for button widget is shown below −
button buttonName options
Options
The options available for the button widget are listed below in table −
Sr.No. | Syntax & Description |
---|---|
1 | -font fontDescriptor Used to set font for widget. |
2 | -height number Used to set height for widget. |
3 | -command action Sets the command action for button. |
4 | -text text Sets the text for the widget. |
5 | -width number Sets the width for widget. |
A simple button widget is shown below −
#!/usr/bin/wish grid [label .myLabel -text "Click the buttons" -textvariable labelText] grid [button .myButton1 -text "Button 1" -font {Helvetica -18 bold} -height 5 -width 10 -command "set labelText clicked_top_btn"] grid [button .myButton2 -text "Button 2" -font {Helvetica -18 bold} -height 5 -width 10 -command "set labelText clicked_bottom_btn"]
When we run the above program, we will get the following output −

When we click the Button1, we will get the following output −

When we click the Button2, we will get the following output −

tk_basic_widgets.htm
Advertisements