Tcl/Tk Cookbook - Basics of Tk


Step 1: Create a frame to contain the button and the set of attribute - value pair

Script
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).

#!/usr/bin/wish -f
Follow this with the lines:
frame .rc -borderwidth 2
wm title . "Resources"
pack .rc
The first of these lines causes Tk to create a simple frame widget with a borderwidth of 2 pixels, name .rc and as the child of the root ".", the wish shell. Frame is a rectangular container used for placing hierarchy of widget children. Frames don't respond to user events and have no default bindings.

The second lines sets the title of the application root window to "Resources". wm is the Tk command for Tk applications to communicate with whatever window manager you are running on your display. wm should be given a top-level window as one of the arguments to set or get information about.

Note: For a full summary of the wm command and how they affect the appearance and behaviour of your application windows, refer to Tk manual pages and/or Chapter 22 of reference [1].

The last line "pack .rc" invokes packer the Tk geometry manger to calculate the size and position of the window and frame and make the frame appear on the screen. Note that since no default size is given, the frame will appear with minimal size. When you pack other widget children within, the geometry manager will automatically resize the frame. You can also set initial values for width and height by appending, for example -width 50 after to the frame creation line.

Create this script and execute it by typing appl1.tcl at command line (don't forget to make the file executable first). The result should look like: