]> git.zerfleddert.de Git - micropolis/blob - src/tk/library/demos/widget
Import Micropolis from http://www.donhopkins.com/home/micropolis/
[micropolis] / src / tk / library / demos / widget
1 #!/usr/local/bin/wish -f
2 #
3 # This script demonstrates the various widgets provided by Tk,
4 # along with many of the features of the Tk toolkit.
5
6 set auto_path "$tk_library/demos $auto_path"
7 wm title . "Widget Demonstration"
8
9 #-------------------------------------------------------
10 # The code below create the main window, consisting of a
11 # menu bar and a message explaining the basic operation
12 # of the program.
13 #-------------------------------------------------------
14
15 frame .menu -relief raised -borderwidth 1
16 message .msg -font -Adobe-times-medium-r-normal--*-180* -relief raised -width 500 \
17 -borderwidth 1 -text "This application demonstrates the widgets provided by the Tk toolkit. The menus above are organized by widget type: each menu contains one or more demonstrations of a particular type of widget. To invoke a demonstration, press mouse button 1 over one of the menu buttons above, drag the mouse to the desired entry in the menu, then release the mouse button.
18
19 To exit this demonstration, invoke the \"Quit\" entry in the \"Misc\" menu."
20
21 pack append . .menu {top fillx} .msg {bottom expand fill}
22
23 #-------------------------------------------------------
24 # The code below creates all the menus, which invoke procedures
25 # to create particular demonstrations of various widgets.
26 #-------------------------------------------------------
27
28 menubutton .menu.button -text "Labels/Buttons" -menu .menu.button.m \
29 -underline 7
30 menu .menu.button.m
31 .menu.button.m add command -label "Labels" -command "mkLabel" -underline 0
32 .menu.button.m add command -label "Buttons" -command "mkButton" -underline 0
33 .menu.button.m add command -label "Checkbuttons" -command "mkCheck" \
34 -underline 0
35 .menu.button.m add command -label "Radiobuttons" -command "mkRadio" \
36 -underline 0
37 .menu.button.m add command -label "15-puzzle" -command "mkPuzzle" -underline 0
38 .menu.button.m add command -label "Iconic buttons" -command "mkIcon" \
39 -underline 0
40
41 menubutton .menu.listbox -text "Listboxes" -menu .menu.listbox.m -underline 0
42 menu .menu.listbox.m
43 .menu.listbox.m add command -label "States" -command "mkListbox" -underline 0
44 .menu.listbox.m add command -label "Colors" -command "mkListbox2" -underline 0
45 .menu.listbox.m add command -label "Well-known sayings" -command mkListbox3 \
46 -underline 0
47
48 menubutton .menu.entry -text "Entries" -menu .menu.entry.m -underline 0
49 menu .menu.entry.m
50 .menu.entry.m add command -label "Without scrollbars" -command "mkEntry" \
51 -underline 4
52 .menu.entry.m add command -label "With scrollbars" -command "mkEntry2" \
53 -underline 0
54
55 menubutton .menu.text -text "Text" -menu .menu.text.m -underline 0
56 menu .menu.text.m
57 .menu.text.m add command -label "Basic text" -command "mkBasic" \
58 -underline 0
59 .menu.text.m add command -label "Display styles" -command "mkStyles" \
60 -underline 0
61 .menu.text.m add command -label "Command bindings" -command "mkTextBind" \
62 -underline 0
63
64 menubutton .menu.scroll -text "Scrollbars" -menu .menu.scroll.m -underline 0
65 menu .menu.scroll.m
66 .menu.scroll.m add command -label "Vertical" -command "mkListbox2" -underline 0
67 .menu.scroll.m add command -label "Horizontal" -command "mkEntry2" -underline 0
68
69 menubutton .menu.scale -text "Scales" -menu .menu.scale.m -underline 2
70 menu .menu.scale.m
71 .menu.scale.m add command -label "Vertical" -command "mkVScale" -underline 0
72 .menu.scale.m add command -label "Horizontal" -command "mkHScale" -underline 0
73
74 menubutton .menu.canvas -text "Canvases" -menu .menu.canvas.m -underline 0
75 menu .menu.canvas.m
76 .menu.canvas.m add command -label "Item types" -command mkItems -underline 0
77 .menu.canvas.m add command -label "2-D plot" -command mkPlot -underline 0
78 .menu.canvas.m add command -label "Text" -command mkCanvText -underline 0
79 .menu.canvas.m add command -label "Arrow shapes" -command mkArrow -underline 0
80 .menu.canvas.m add command -label "Ruler" -command mkRuler -underline 0
81 .menu.canvas.m add command -label "Scrollable canvas" -command mkScroll \
82 -underline 0
83
84 menubutton .menu.menu -text "Menus" -menu .menu.menu.m -underline 0
85 menu .menu.menu.m
86 .menu.menu.m add command -label "Print hello" -command {puts stdout "Hello"} \
87 -accelerator Control+a -underline 6
88 bind .msg <Control-a> {puts stdout "Hello"}
89 .menu.menu.m add command -label "Print goodbye" -command {\
90 puts stdout "Goodbye"} -accelerator Control+b -underline 6
91 bind .msg <Control-b> {puts stdout "Goodbye"}
92 .menu.menu.m add command -label "Light blue background" \
93 -command {.msg config -bg "LightBlue1"} -underline 0
94 .menu.menu.m add command -label "Info on tear-off menus" -command mkTear \
95 -underline 0
96 .menu.menu.m add cascade -label "Check buttons =>" -menu .menu.menu.m.check \
97 -underline 0
98 .menu.menu.m add cascade -label "Radio buttons =>" -menu .menu.menu.m.radio \
99 -underline 0
100 .menu.menu.m add command -bitmap @$tk_library/demos/bitmaps/pattern \
101 -command {
102 mkDialog .pattern {-text {The menu entry you invoked displays a bitmap rather than a text string. Other than this, it is just like any other menu entry.} -aspect 250} {OK {}}
103 }
104
105 menu .menu.menu.m.check
106 .menu.menu.m.check add check -label "Oil checked" -variable oil
107 .menu.menu.m.check add check -label "Transmission checked" -variable trans
108 .menu.menu.m.check add check -label "Brakes checked" -variable brakes
109 .menu.menu.m.check add check -label "Lights checked" -variable lights
110 .menu.menu.m.check add separator
111 .menu.menu.m.check add command -label "Show current values" \
112 -command "showVars .menu.menu.dialog oil trans brakes lights"
113 .menu.menu.m.check invoke 1
114 .menu.menu.m.check invoke 3
115
116 menu .menu.menu.m.radio
117 .menu.menu.m.radio add radio -label "10 point" -variable pointSize -value 10
118 .menu.menu.m.radio add radio -label "14 point" -variable pointSize -value 14
119 .menu.menu.m.radio add radio -label "18 point" -variable pointSize -value 18
120 .menu.menu.m.radio add radio -label "24 point" -variable pointSize -value 24
121 .menu.menu.m.radio add radio -label "32 point" -variable pointSize -value 32
122 .menu.menu.m.radio add sep
123 .menu.menu.m.radio add radio -label "Roman" -variable style -value roman
124 .menu.menu.m.radio add radio -label "Bold" -variable style -value bold
125 .menu.menu.m.radio add radio -label "Italic" -variable style -value italic
126 .menu.menu.m.radio add sep
127 .menu.menu.m.radio add command -label "Show current values" -command \
128 "showVars .menu.menu.dialog pointSize style"
129 .menu.menu.m.radio invoke 1
130 .menu.menu.m.radio invoke 7
131
132 menubutton .menu.misc -text Misc -menu .menu.misc.m -underline 1
133 menu .menu.misc.m
134 .menu.misc.m add command -label "Modal dialog (local grab)" -command {
135 mkDialog .modal {-text {This dialog box is a modal one. It uses Tk's "grab" command to create a "local grab" on the dialog box. The grab prevents any pointer-related events from getting to any other windows in the application. If you press the "OK" button below (or hit the Return key) then the dialog box will go away and things will return to normal.} -aspect 250 -justify left} {OK {}}
136 dpos .modal
137 bind .modal <Visibility> {grab .modal; focus .modal}
138 } -underline 0
139 .menu.misc.m add command -label "Modal dialog (global grab)" -command {
140 mkDialog .modal {-text {This is another modal dialog box. However, in this case a "global grab" is used, which locks up the display so you can't talk to any windows in any applications anywhere, except for the dialog. If you press the "OK" button below (or hit the Return key) then the dialog box will go away and things will return to normal.} -aspect 250 -justify left} {OK {}}
141 dpos .modal
142 bind .modal <Visibility> {grab -global .modal; focus .modal}
143 } -underline 0
144 .menu.misc.m add command -label "Quit" -command "destroy ." -underline 0
145
146 pack append .menu .menu.button left .menu.listbox left \
147 .menu.entry left .menu.text left .menu.scroll left .menu.scale left \
148 .menu.canvas left .menu.menu left .menu.misc left
149
150 # Set up for keyboard-based menu traversal
151
152 tk_bindForTraversal .msg
153 bind . <Any-Enter> {focus .msg}
154 tk_menus . .menu.button .menu.listbox .menu.entry .menu.text \
155 .menu.scroll .menu.scale .menu.canvas .menu.menu .menu.misc
156
157 # Position a dialog box at a reasonable place on the screen.
158
159 proc dpos w {
160 wm geometry $w +300+300
161 }
Impressum, Datenschutz