1Tk::ColoredButton(3) User Contributed Perl Documentation Tk::ColoredButton(3)
2
3
4
6 Tk::ColoredButton - Button widget with background gradient color.
7
9 #!/usr/bin/perl
10 use strict;
11 use warnings;
12
13 use Tk;
14 use Tk::ColoredButton;
15
16 my $mw = MainWindow->new( -background => 'white', -title => 'ColoredButton example' );
17 $mw->minsize( 300, 300 );
18
19 my $coloredbutton = $mw->ColoredButton(
20 -text => 'ColoredButton1',
21 -autofit => 1,
22 -font => '{arial} 12 bold',
23 -command => [ \&display, 'ColoredButton1' ],
24 )->pack(qw/-padx 10 -pady 10 /);
25
26 my $coloredbutton2 = $mw->ColoredButton(
27 -text => 'ColoredButton2',
28 -font => '{arial} 12 bold',
29 -command => [ \&display, 'ColoredButton2' ],
30 -height => 40,
31 -width => 160,
32 -gradient => {
33 -start_color => '#FFFFFF',
34 -end_color => '#BFD4E8',
35 -type => 'mirror_vertical',
36 -start => 50,
37 -number_color => 10
38 },
39 -activegradient => {
40 -start_color => '#BFD4E8',
41 -end_color => '#FFFFFF',
42 -type => 'mirror_vertical',
43 -start => 50,
44 -number_color => 10
45 },
46 -tooltip => 'my button message',
47 )->pack(qw/-padx 10 -pady 10 /);
48 $coloredbutton2->flash();
49
50 my $button = $mw->Button(
51 -activebackground => 'yellow',
52 -background => 'green',
53 -text => 'Real Button',
54 -font => '{arial} 12 bold',
55 -command => [ \&display, 'Button' ],
56 )->pack(qw/-ipadx 10 -pady 10 /);
57
58 MainLoop;
59
60 sub display {
61 my $message = shift;
62 if ($message) { print "$message\n"; }
63 }
64
66 Tk::ColoredButton is an extension of the Tk::Canvas::GradientColor
67 widget. It is an easy way to simulate a button widget with gradient
68 background color.
69
71 The following Tk::Button options are supported :
72
73 -activebackground -activeforeground -anchor
74 -background -bitmap -borderwidth -command
75 -compound -cursor -disabledforeground -font
76 -foreground -height -highlightbackground -highlightcolor
77 -highlightthickness -image -justify -padx
78 -pady -relief -repeatdelay -repeatinterval
79 -state -takefocus -text -textvariable
80 -width -wraplength
81
83 There are many options which allow you to configure your button as you
84 want.
85
86 Name: activeGradient
87 Class: ActiveGradient
88 Switch: -activegradient => hash reference
89 Specifies gradient background color to use when the mouse cursor is
90 positioned over the button. Please read the options of the
91 set_gradientcolor method of Tk::Canvas::GradientColor to understand
92 the options.
93
94 -activegradient => {
95 -start_color => '#BFD4E8',
96 -end_color => '#FFFFFF',
97 -type => 'mirror_vertical',
98 -start => 50,
99 -number_color => 10
100 },
101
102 Default : { -start_color => '#FFFFFF', -end_color => '#B2B2B2' }
103
104 Name: autofit
105 Class: Autofit
106 Switch: -autofit => 1 or 0
107 Enables automatic adjustment (width and height) of the button
108 depending on the displayed content (text, image, bitmap, ...).
109
110 -autofit => 1,
111
112 Default : 0
113
114 Name: gradient
115 Class: Gradient
116 Switch: -gradient
117 Specifies gradient background color on the button. Please read the
118 options of the set_gradientcolor method of "set_gradientcolor" in
119 Tk::Canvas::GradientColor to understand the options.
120
121 -gradient => {
122 -start_color => '#FFFFFF',
123 -end_color => '#BFD4E8',
124 -type => 'mirror_vertical',
125 -start => 50,
126 -number_color => 10
127 },
128
129 Default : { -start_color => '#B2B2B2', -end_color => '#FFFFFF' }
130
131 -height or -width
132 Specifies a desired window height/width that the button widget
133 should request from its geometry manager. The value may be
134 specified in any of the forms described in the "COORDINATES" in
135 Tk::Canvas section below.
136
137 You can also use the autofit option if you want to have an
138 automatic adjustment for your button.
139
140 Default : -height => 20, -width => 80,
141
142 Name: imageDisabled
143 Class: ImageDisabled
144 Switch: -imagedisabled => $image_photo
145 Specifies an image to display in the button when it is disabled. (
146 See Tk::Photo or Tk::Image for details of image creation.).
147
148 -imagedisabled => $image_photo,
149
150 Default : undef
151
152 Name: tooltip
153 Class: Tooltip
154 Switch: -tooltip => $tooltip or [$tooltip, $iniwait?]
155 Creates and attaches help balloons (using Tk::Balloon). Then, when
156 the mouse pauses over the button, a help balloon is popped up.
157
158 $iniwait Specifies the amount of time to wait without activity
159 before popping up a help balloon. Specified in milliseconds.
160 Defaults to 350 milliseconds. This applies to both the popped up
161 balloon and the status bar message.
162
163 -tooltip => 'my button message',
164 -tooltip => ['my button message', 200],
165
166 Default : undef
167
169 You can use invoke method like in Tk::Button.
170
171 delete_tooltip
172 $button_bgc->delete_tooltip
173 Delete the help balloon created with tooltip option.
174
175 $button_bgc->delete_tooltip;
176
177 flash
178 $button_bgc->flash(?$interval) in ms
179 Flash the button. This is accomplished by change foreground color
180 of the button several times, alternating between active and normal
181 colors. At the end of the flash the button is left in the same
182 normal/active state as when the command was invoked. This command
183 is ignored if the button's state is disabled.
184
185 $interval is the time in milliseconds between each alternative.
186
187 If $interval is not specified, the button will alternate between
188 active and normal colors every 300 milliseconds.
189
190 If $interval is zero, any current flash operation will be cancel.
191
192 If $interval is non-zero, the button will alternate every $interval
193 milliseconds until it is explicitly cancelled via $interval to zero
194 or using cancel method to id returned.
195
196 my $id = $button_bgc->flash(1000);
197 $button_bgc->flash(0); # Cancel the flash
198
199 redraw_button
200 $button_bgc->redraw_button
201 Re-creates the button. Tk::ColoredButton supports the configure and
202 cget methods described in the Tk::options manpage. If you use
203 configure method to change a widget specific option, the
204 modification will not be display. You have to update your widget by
205 redraw it using this method.
206
207 $button_bgc->redraw_button;
208
210 Djibril Ousmanou, "<djibel at cpan.org>"
211
213 Please report any bugs or feature requests to "bug-tk-coloredbutton at
214 rt.cpan.org", or through the web interface at
215 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-ColoredButton>. I
216 will be notified, and then you'll automatically be notified of progress
217 on your bug as I make changes.
218
220 See also Tk::StyledButton and Tk::Button.
221
223 You can find documentation for this module with the perldoc command.
224
225 perldoc Tk::ColoredButton
226
227 You can also look for information at:
228
229 • RT: CPAN's request tracker
230
231 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-ColoredButton>
232
233 • AnnoCPAN: Annotated CPAN documentation
234
235 <http://annocpan.org/dist/Tk-ColoredButton>
236
237 • CPAN Ratings
238
239 <http://cpanratings.perl.org/d/Tk-ColoredButton>
240
241 • Search CPAN
242
243 <http://search.cpan.org/dist/Tk-ColoredButton/>
244
247 Copyright 2011 Djibril Ousmanou.
248
249 This program is free software; you can redistribute it and/or modify it
250 under the terms of either: the GNU General Public License as published
251 by the Free Software Foundation; or the Artistic License.
252
253 See http://dev.perl.org/licenses/ for more information.
254
255
256
257perl v5.34.0 2022-01-21 Tk::ColoredButton(3)