BtnBox.tcl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: BtnBox.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "widget": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program using tixwish.
  12. # This file demonstrates the use of the tixButtonBox widget, which is a
  13. # group of TK buttons. You can use it to manage the buttons in a dialog box,
  14. # for example.
  15. #
  16. proc RunSample {w} {
  17. # Create the label on the top of the dialog box
  18. #
  19. label $w.top -padx 20 -pady 10 -border 1 -relief raised -anchor c -text \
  20. "This dialog box is\n a demostration of the\n tixButtonBox widget"
  21. # Create the button box and add a few buttons in it. Set the
  22. # -width of all the buttons to the same value so that they
  23. # appear in the same size.
  24. #
  25. # Note that the -text, -underline, -command and -width options are all
  26. # standard options of the button widgets.
  27. #
  28. tixButtonBox $w.box -orientation horizontal
  29. $w.box add ok -text OK -underline 0 -command "destroy $w" -width 5
  30. $w.box add close -text Close -underline 0 -command "destroy $w" -width 5
  31. pack $w.box -side bottom -fill x
  32. pack $w.top -side top -fill both -expand yes
  33. # "after 0" is used so that the key bindings won't interfere with
  34. # tkTraverseMenu
  35. #
  36. bind [winfo toplevel $w] <Alt-o> \
  37. "after 0 tkButtonInvoke [$w.box subwidget ok]"
  38. bind [winfo toplevel $w] <Alt-c> \
  39. "after 0 tkButtonInvoke [$w.box subwidget close]"
  40. bind [winfo toplevel $w] <Escape> \
  41. "after 0 tkButtonInvoke [$w.box subwidget close]"
  42. focus [$w.box subwidget ok]
  43. }
  44. if {![info exists tix_demo_running]} {
  45. wm withdraw .
  46. set w .demo
  47. toplevel $w; wm transient $w ""
  48. RunSample $w
  49. bind $w <Destroy> exit
  50. }