Version 3 of A little value dialog

Updated 2003-04-02 15:17:20

Richard Suchenwirth 2003-04-02 - Here is a custom dialog - a toplevel that prompts for a value:

http://mini.net/files/valuedialog.jpg


 proc value_dialog {string} {
    set w [toplevel .[clock seconds]]
    wm resizable $w 0 0
    wm title $w "Value request"
    label  $w.l -text $string
    entry  $w.e -textvar $w -bg white
    bind $w.e <Return> {set done 1}
    button $w.ok     -text OK     -command {set done 1}
    button $w.c      -text Clear  -command "set $w {}"
    button $w.cancel -text Cancel -command "set $w {}; set done 1"
    grid $w.l  -    -        -sticky news
    grid $w.e  -    -        -sticky news
    grid $w.ok $w.c $w.cancel
    vwait done
    destroy $w
    set ::$w
 }

#----- Test

 set test [value_dialog "Give me a value please:"]
 puts test:$test

MSW: I wouldn't specify the entry's background, for a real reusable dialog, I'd check the option database to see if something exists.

Imho such little snippets should use a global option hierarchy so you can easily integrate them into application which use the option database themselves. Aside of that, nice...

MSW: What is not so nice is that you set result to "" instead of setting $w to "". I've changed that.


Arts and crafts of Tcl-Tk programming