Previous: Using check buttons
Up: Widgets
Next: Scrolling and scrollbar widgets
Previous Page: Using check buttons
Next Page: Scrolling and scrollbar widgets

Modifying the application to display pre-stored data

The application as developed so far can be used to input data and save it to a file. Two useful modifications can be made - firstly to clear all the data, and secondly to initialise the data to data stored in an appropriate input file - which for simplicity we shall call ÒinputfileÓ.

To provide the clear data facility, we shall simply add a new button

button .clear -text Clear -command {ClearData}

and a new procedure

proc ClearData {} {
       set firstname1 ""
       set surname1 ""
       set address1 ""
       set telephone ""
       set age1 ""
       set sex Male
         #or female if you prefer!
       }

To provide the Load facility, a Load button is provided

button .load -text Load -command {LoadData}

and a new procedure

proc LoadData {} {
        set infile [open inputfile r]
        gets $infile $firstname1
        gets $infile $surname1
        gets $infile $address1
        gets $infile $telephone
        gets $infile $age1
        gets $infile $sex
        }

Care should be taken to initialise the button state for the Sex property. Care should also be taken while packing the buttons for Clear and Load, which is perhaps best handled by the use of another frame.

These are left as a exercises for the reader.

This completes this simple application.

csstddm@brunel.ac.uk
Fri Aug 19 16:55:19 BST 1994