Posted to tcl by patthoyts at Sun Feb 10 16:35:31 GMT 2008view raw
- proc Form {parent} {
- set dlg [toplevel $parent.mydialog -class Dialog]
- wm withdraw $dlg
- wm title $dlg "My form"
- wm transient $dlg $parent
- variable $dlg
- set State [namespace which -variable $dlg]
- upvar #0 $State state
- array set $dlg {thingOne 1 thingTwo 0 ok ""}
- ttk::checkbutton $dlg.t1 -text "Thing one" -underline 8 -variable $State\(thingOne\)
- ttk::checkbutton $dlg.t2 -text "Thing two" -underline 8 -variable $State\(thingTwo\)
- ttk::button $dlg.ok -text "OK" -default active -command [list set $State\(ok\) ok]
- ttk::button $dlg.cancel -text "Cancel" -command [list set $State\(ok\) cancel]
- bind $dlg <Return> [list $dlg.ok invoke]
- bind $dlg <Escape> [list $dlg.cancel invoke]
- wm protocol $dlg WM_DELETE_WINDOW [list $dlg.cancel invoke]
- grid $dlg.t1 - -sticky news
- grid $dlg.t2 - -sticky news
- grid $dlg.ok $dlg.cancel -sticky se
- grid columnconfigure $dlg 0 -weight 1
- grid rowconfigure $dlg 2 -weight 1
- wm deiconify $dlg
- tkwait variable $State\(ok\)
- if {$state(ok) eq "ok"} {
- # dialog was accepted: do ok stuff.
- }
- unset $dlg
- destroy $dlg
- }