Start by placing the following script in ed.tcl:
#! /usr/bin/wish -f global GotSelection set GotSelection 0 frame .fr -width 10c -height 5c ;#main window wm title . "Simple Text Editor V 0" pack .fr #configure menubar on top frame .menubar -relief raised -bd 2 pack .menubar -in .fr -fill x frame .edf #put a text widget with scroll bars text .ed -width 80 -height 20 -bg grey \ -yscrollcommand ".ys set" scrollbar .ys -command ".ed yview" pack .ed .ys -in .edf -side left -fill y pack .edf -in .fr -after .menubar -fill x
The first line of the script is the command to shell process to invoke the wish shell and pass this file as the script that wish should interpret (parse).
The next line declares a global variable GotSelection and follows it with initialising it to the boolean value zero [Note that as far as Tcl parser is concerned "set GotSelection 0" is a string with three elements.].
The next three lines create and pack a base frame ".fr" whose width is 10 centimeters and height 5 centimeters; the root window is titled "Simple Text Editor V 0"
For this text editor, we want to create a menubar at the top of the main window for supporting File, Edit and Find actions. In Tk, the menubar is a frame widget with one menubutton for each menu (usually pulldown). The option -relief takes the value raised or sunken to give a raised or depressed appearance to the widget. The option -fill (usually used for scrollbars, menubars etc.) takes "x" or "y" as argument to extend the widget in the horizontal or vertical direction up to the end of the parents border in that direction.
The next group of lines create a text widget ".ed" and a vertical scrollbar, packs them inside the frame ".edf" in the main window.
-yscrollcommand ".ys set" connects the ".ys" scrollbar's command .ed yview, connecting the text and scrollbar.
The "-after" option tells the packer to pack the frame containg the text widget and scrollbar below the top menubar and the option "-side" tells it to pack the vertical scrollbar to the left of the text widget.
Make ed.tcl executable and run it the final result should be similar to: