1button(n) Tk Built-In Commands button(n)
2
3
4
5______________________________________________________________________________
6
8 button - Create and manipulate button widgets
9
11 button pathName ?options?
12
14 -activebackground -font -relief
15 -activeforeground -foreground -repeatdelay
16 -anchor -highlightbackground -repeatinterval
17 -background -highlightcolor -takefocus
18 -bitmap -highlightthickness -text
19 -borderwidth -image -textvariable
20 -compound -justify -underline
21 -cursor -padx -wraplength
22 -disabledforeground -pady
23
24 See the options manual entry for details on the standard options.
25
27 [-command command] Specifies a Tcl command to associate with the but‐
28 ton. This command is typically invoked when mouse button 1 is released
29 over the button window. [-default default] Specifies one of three
30 states for the default ring: normal, active, or disabled. In active
31 state, the button is drawn with the platform specific appearance for a
32 default button. In normal state, the button is drawn with the platform
33 specific appearance for a non-default button, leaving enough space to
34 draw the default button appearance. The normal and active states will
35 result in buttons of the same size. In disabled state, the button is
36 drawn with the non-default button appearance without leaving space for
37 the default appearance. The disabled state may result in a smaller
38 button than the active state. [-height height] Specifies a desired
39 height for the button. If an image or bitmap is being displayed in the
40 button then the value is in screen units (i.e. any of the forms accept‐
41 able to Tk_GetPixels); for text it is in lines of text. If this option
42 is not specified, the button's desired height is computed from the size
43 of the image or bitmap or text being displayed in it. [-overre‐
44 lief overRelief] Specifies an alternative relief for the button, to be
45 used when the mouse cursor is over the widget. This option can be used
46 to make toolbar buttons, by configuring -relief flat -overrelief
47 raised. If the value of this option is the empty string, then no
48 alternative relief is used when the mouse cursor is over the button.
49 The empty string is the default value. [-state state] Specifies one of
50 three states for the button: normal, active, or disabled. In normal
51 state the button is displayed using the foreground and background
52 options. The active state is typically used when the pointer is over
53 the button. In active state the button is displayed using the active‐
54 Foreground and activeBackground options. Disabled state means that the
55 button should be insensitive: the default bindings will refuse to
56 activate the widget and will ignore mouse button presses. In this
57 state the disabledForeground and background options determine how the
58 button is displayed. [-width width] Specifies a desired width for the
59 button. If an image or bitmap is being displayed in the button then
60 the value is in screen units (i.e. any of the forms acceptable to
61 Tk_GetPixels). For a text button (no image or with -compound none)
62 then the width specifies how much space in characters to allocate for
63 the text label. If the width is negative then this specifies a minimum
64 width. If this option is not specified, the button's desired width is
65 computed from the size of the image or bitmap or text being displayed
66 in it.
67_________________________________________________________________
68
69
71 The button command creates a new window (given by the pathName argu‐
72 ment) and makes it into a button widget. Additional options, described
73 above, may be specified on the command line or in the option database
74 to configure aspects of the button such as its colors, font, text, and
75 initial relief. The button command returns its pathName argument. At
76 the time this command is invoked, there must not exist a window named
77 pathName, but pathName's parent must exist.
78
79 A button is a widget that displays a textual string, bitmap or image.
80 If text is displayed, it must all be in a single font, but it can
81 occupy multiple lines on the screen (if it contains newlines or if
82 wrapping occurs because of the wrapLength option) and one of the char‐
83 acters may optionally be underlined using the underline option. It can
84 display itself in either of three different ways, according to the
85 state option; it can be made to appear raised, sunken, or flat; and it
86 can be made to flash. When a user invokes the button (by pressing
87 mouse button 1 with the cursor over the button), then the Tcl command
88 specified in the -command option is invoked.
89
90
92 The button command creates a new Tcl command whose name is pathName.
93 This command may be used to invoke various operations on the widget.
94 It has the following general form:
95 pathName option ?arg arg ...?
96 Option and the args determine the exact behavior of the command. The
97 following commands are possible for button widgets:
98
99 pathName cget option
100 Returns the current value of the configuration option given by
101 option. Option may have any of the values accepted by the but‐
102 ton command.
103
104 pathName configure ?option? ?value option value ...?
105 Query or modify the configuration options of the widget. If no
106 option is specified, returns a list describing all of the avail‐
107 able options for pathName (see Tk_ConfigureInfo for information
108 on the format of this list). If option is specified with no
109 value, then the command returns a list describing the one named
110 option (this list will be identical to the corresponding sublist
111 of the value returned if no option is specified). If one or
112 more option-value pairs are specified, then the command modifies
113 the given widget option(s) to have the given value(s); in this
114 case the command returns an empty string. Option may have any
115 of the values accepted by the button command.
116
117 pathName flash
118 Flash the button. This is accomplished by redisplaying the but‐
119 ton several times, alternating between active and normal colors.
120 At the end of the flash the button is left in the same nor‐
121 mal/active state as when the command was invoked. This command
122 is ignored if the button's state is disabled.
123
124 pathName invoke
125 Invoke the Tcl command associated with the button, if there is
126 one. The return value is the return value from the Tcl command,
127 or an empty string if there is no command associated with the
128 button. This command is ignored if the button's state is dis‐
129 abled.
130
131
133 Tk automatically creates class bindings for buttons that give them
134 default behavior:
135
136 [1] A button activates whenever the mouse passes over it and deacti‐
137 vates whenever the mouse leaves the button. Under Windows, this
138 binding is only active when mouse button 1 has been pressed over
139 the button.
140
141 [2] A button's relief is changed to sunken whenever mouse button 1
142 is pressed over the button, and the relief is restored to its
143 original value when button 1 is later released.
144
145 [3] If mouse button 1 is pressed over a button and later released
146 over the button, the button is invoked. However, if the mouse
147 is not over the button when button 1 is released, then no invo‐
148 cation occurs.
149
150 [4] When a button has the input focus, the space key causes the but‐
151 ton to be invoked.
152
153 If the button's state is disabled then none of the above actions occur:
154 the button is completely non-responsive.
155
156 The behavior of buttons can be changed by defining new bindings for
157 individual widgets or by redefining the class bindings.
158
159
161 This is the classic Tk “Hello, World!” demonstration:
162
163 button .b -text "Hello, World!" -command exit
164 pack .b
165
166 This example demonstrates how to handle button accelerators:
167
168 button .b1 -text Hello -underline 0
169 button .b2 -text World -underline 0
170 bind . <Key-h> {.b1 flash; .b1 invoke}
171 bind . <Key-w> {.b2 flash; .b2 invoke}
172 pack .b1 .b2
173
175 ttk::button(n)
176
178 button, widget
179
180
181
182Tk 4.4 button(n)