msgbox.tcl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # msgbox.tcl --
  2. #
  3. # This demonstration script creates message boxes of various type
  4. if {![info exists widgetDemo]} {
  5. error "This script should be run from the \"widget\" demo."
  6. }
  7. package require Tk
  8. package require Ttk
  9. set w .msgbox
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Message Box Demonstration"
  13. wm iconname $w "messagebox"
  14. positionWindow $w
  15. label $w.msg -font $font -wraplength 4i -justify left -text "Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box."
  16. pack $w.msg -side top
  17. pack [addSeeDismiss $w.buttons $w {} {
  18. ttk::button $w.buttons.vars -text "Message Box" -command "showMessageBox $w"
  19. }] -side bottom -fill x
  20. #pack $w.buttons.dismiss $w.buttons.code $w.buttons.vars -side left -expand 1
  21. frame $w.left
  22. frame $w.right
  23. pack $w.left $w.right -side left -expand yes -fill y -pady .5c -padx .5c
  24. label $w.left.label -text "Icon"
  25. frame $w.left.sep -relief ridge -bd 1 -height 2
  26. pack $w.left.label -side top
  27. pack $w.left.sep -side top -fill x -expand no
  28. set msgboxIcon info
  29. foreach i {error info question warning} {
  30. radiobutton $w.left.b$i -text $i -variable msgboxIcon \
  31. -relief flat -value $i -width 16 -anchor w
  32. pack $w.left.b$i -side top -pady 2 -anchor w -fill x
  33. }
  34. label $w.right.label -text "Type"
  35. frame $w.right.sep -relief ridge -bd 1 -height 2
  36. pack $w.right.label -side top
  37. pack $w.right.sep -side top -fill x -expand no
  38. set msgboxType ok
  39. foreach t {abortretryignore ok okcancel retrycancel yesno yesnocancel} {
  40. radiobutton $w.right.$t -text $t -variable msgboxType \
  41. -relief flat -value $t -width 16 -anchor w
  42. pack $w.right.$t -side top -pady 2 -anchor w -fill x
  43. }
  44. proc showMessageBox {w} {
  45. global msgboxIcon msgboxType
  46. set button [tk_messageBox -icon $msgboxIcon -type $msgboxType \
  47. -title Message -parent $w\
  48. -message "This is a \"$msgboxType\" type messagebox with the \"$msgboxIcon\" icon"]
  49. tk_messageBox -icon info -message "You have selected \"$button\"" -type ok\
  50. -parent $w
  51. }