Tcl/Tk Tutorial

Hello World in Tcl:

   # hello.tcl
   puts "Hello, World!"

Variables:

   # variables.tcl
   set name "John"
   set age 25

   puts "Name: $name"
   puts "Age: $age"

Tk Basics

Creating a Simple Tk Window:

   # 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

Button Click Event:

   # 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

Entry Widget:

   # 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

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