Tcl Basics:

1. Hello World in Tcl:

 ```tcl
 # hello.tcl
 puts "Hello, World!"
 ```
 Save the above code in a file named `hello.tcl` and run it using the Tcl interpreter:
 ```bash
 tclsh hello.tcl
 ```

2. Variables:

 ```tcl
 # variables.tcl
 set name "John"
 set age 25
 puts "Name: $name"
 puts "Age: $age"
 ```

Tk Basics:

3. Creating a Simple Tk Window:

 ```tcl
 # simple_window.tcl
 package require Tk
 # Create a new top-level window
 wm title . "Simple Window"
 wm geometry . 300x200
 # Display a label in the window
 label .label -text "Hello, Tk!" -font {Helvetica 16}
 pack .label -padx 20 -pady 20
 ```
 Run it with:
 ```bash
 wish simple_window.tcl
 ```

4. Button Click Event:

 ```tcl
 # button_click.tcl
 package require Tk
 # Function to be executed on button click
 proc buttonClick {} {
     puts "Button Clicked!"
 }
 # Create a window and a button
 wm title . "Button Click Event"
 button .btn -text "Click me!" -command buttonClick
 pack .btn -padx 20 -pady 20
 ```
 Run it with:
 ```bash
 wish button_click.tcl
 ```

5. Entry Widget:

 ```tcl
 # entry_widget.tcl
 package require Tk
 # Function to be executed on button click
 proc showInput {} {
     set inputValue [.entry get]
     puts "Input Value: $inputValue"
 }
 # Create a window, an entry widget, and a button
 wm title . "Entry Widget"
 entry .entry
 button .btn -text "Show Input" -command showInput
 # Pack the widgets
 pack .entry -padx 20 -pady 10
 pack .btn -pady 10
 ```
 Run it with:
 ```bash
 wish entry_widget.tcl
 ```
We use cookies to personalize and enhance your experience on our site. By using our site, you agree to our use of cookies.
  More information about cookies