[Richard Suchenwirth] 2006-06-07 - Here is a [Tk] dialog that can be used with [another simple database] to edit a record (a list) by fields. Similar to [tk_getOpenFile] etc., "" is returned when the user clicked "Cancel", else the current field contents. It is up to the caller to do something useful with the result :^) [http://mini.net/files/editRecord.jpg] ---- package require Tk proc editRecord {title headers fields} { set oldfocus [focus] set w [toplevel .[clock clicks]] wm resizable $w 1 0 wm title $w $title set n 0 foreach h $headers f $fields { label $w.h$n -text $h -anchor e [entry $w.e$n -width [string length $f]] insert end $f grid $w.h$n $w.e$n -sticky news incr n } button $w.ok -text OK -width 5 -command [list set $w 1] button $w.cancel -text Cancel -command [list set $w 0] grid $w.ok $w.cancel -pady 5 grid columnconfigure $w 1 -weight 1 vwait ::$w if [set ::$w] { #-- collect the current entry contents set n 0 foreach f $fields { lappend res [$w.e$n get] incr n } } else {set res {}} destroy $w unset ::$w ;#-- clean up the vwait variable focus $oldfocus return $res } #-- Testing: wm withdraw . set db { {Author Title Year Category} {{Shakespeare, William} {Romeo and Juliet} 1767 Theatre} {{Puzo, Mario} {The Godfather} 1965 Drama} {{Verne, Jules} {Around the world in 80 days} 1862 Adventure} {{Sheldon, Sydney} {The other side of midnight} 1967 Mystery} {{Mc Cullough, Colleen} Thornbirds 1967 Saga} } set res [editRecord Edit: [lindex $db 0] [lindex $db 3]] #-- If not canceled, "commit" the changes to the database if [llength $res] {lset db 3 $res} #-- show the current state of the data, to verify changes were applied puts [join $db \n] exit ----- [Robert Abitbol] Very impressive work! Well done, Richard! May I ask you a question? When one opens the file where the data for [another simple database] is stored to have a look at the contents, (say we open the file with Notepad), what do we see? When we are talking about entering the data with fields, we are talking about seing '''all''' the records in the database and not only one. Some people (including yours truly) need a global view of a database. ---- [Arts and crafts of Tcl-Tk programming] | [Category Example] | [Category GUI]