Posted to tcl by patthoyts at Sun Feb 10 16:35:31 GMT 2008view raw

  1. proc Form {parent} {
  2. set dlg [toplevel $parent.mydialog -class Dialog]
  3. wm withdraw $dlg
  4. wm title $dlg "My form"
  5. wm transient $dlg $parent
  6. variable $dlg
  7. set State [namespace which -variable $dlg]
  8. upvar #0 $State state
  9. array set $dlg {thingOne 1 thingTwo 0 ok ""}
  10. ttk::checkbutton $dlg.t1 -text "Thing one" -underline 8 -variable $State\(thingOne\)
  11. ttk::checkbutton $dlg.t2 -text "Thing two" -underline 8 -variable $State\(thingTwo\)
  12. ttk::button $dlg.ok -text "OK" -default active -command [list set $State\(ok\) ok]
  13. ttk::button $dlg.cancel -text "Cancel" -command [list set $State\(ok\) cancel]
  14. bind $dlg <Return> [list $dlg.ok invoke]
  15. bind $dlg <Escape> [list $dlg.cancel invoke]
  16. wm protocol $dlg WM_DELETE_WINDOW [list $dlg.cancel invoke]
  17. grid $dlg.t1 - -sticky news
  18. grid $dlg.t2 - -sticky news
  19. grid $dlg.ok $dlg.cancel -sticky se
  20. grid columnconfigure $dlg 0 -weight 1
  21. grid rowconfigure $dlg 2 -weight 1
  22. wm deiconify $dlg
  23. tkwait variable $State\(ok\)
  24. if {$state(ok) eq "ok"} {
  25. # dialog was accepted: do ok stuff.
  26. }
  27. unset $dlg
  28. destroy $dlg
  29. }