msgbox.tcl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. set w .msgbox
  9. catch {destroy $w}
  10. toplevel $w
  11. wm title $w "Message Box Demonstration"
  12. wm iconname $w "messagebox"
  13. positionWindow $w
  14. 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."
  15. pack $w.msg -side top
  16. pack [addSeeDismiss $w.buttons $w {} {
  17. ttk::button $w.buttons.vars -text "Message Box" -command "showMessageBox $w"
  18. }] -side bottom -fill x
  19. #pack $w.buttons.dismiss $w.buttons.code $w.buttons.vars -side left -expand 1
  20. frame $w.left
  21. frame $w.right
  22. pack $w.left $w.right -side left -expand yes -fill y -pady .5c -padx .5c
  23. label $w.left.label -text "Icon"
  24. frame $w.left.sep -relief ridge -bd 1 -height 2
  25. pack $w.left.label -side top
  26. pack $w.left.sep -side top -fill x -expand no
  27. set msgboxIcon info
  28. foreach i {error info question warning} {
  29. radiobutton $w.left.b$i -text $i -variable msgboxIcon \
  30. -relief flat -value $i -width 16 -anchor w
  31. pack $w.left.b$i -side top -pady 2 -anchor w -fill x
  32. }
  33. label $w.right.label -text "Type"
  34. frame $w.right.sep -relief ridge -bd 1 -height 2
  35. pack $w.right.label -side top
  36. pack $w.right.sep -side top -fill x -expand no
  37. set msgboxType ok
  38. foreach t {abortretryignore ok okcancel retrycancel yesno yesnocancel} {
  39. radiobutton $w.right.$t -text $t -variable msgboxType \
  40. -relief flat -value $t -width 16 -anchor w
  41. pack $w.right.$t -side top -pady 2 -anchor w -fill x
  42. }
  43. proc showMessageBox {w} {
  44. global msgboxIcon msgboxType
  45. set button [tk_messageBox -icon $msgboxIcon -type $msgboxType \
  46. -title Message -parent $w\
  47. -message "This is a \"$msgboxType\" type messagebox with the \"$msgboxIcon\" icon"]
  48. tk_messageBox -icon info -message "You have selected \"$button\"" -type ok\
  49. -parent $w
  50. }