B provides a shaped button with stylized shading,
using a L object to implement the button rendering. The usual
L options and behaviors are preserved as much as possible.
When a button is rendered, 2 versions are created:
=item B version
This version uses the unmodified C<-background> value to render
=item B version
This version uses the uses a brightened version of the C<-background> value
to render the button.
If the L I<(min. version 2.30)> and L modules are installed,
the button images can be rendered via GD and captured for external
Note that some option values (I 'folio', -orient =E 'vertical'>)
are provided for use by L I<(derived from >L I<)>, and
have minimal value for general use.
B supports the following L options:
B<-anchor> B<-background> B<-bitmap> B<-command> B<-compound>
B<-font> B<-foreground> B<-height> B<-image> B<-justify> B<-padx> B<-pady>
B<-state> B<-text> B<-textvariable> B<-width> B<-wraplength>
In addition, the following additional options are supported:
=item B<-activeimage> C<=E> I
When specified with the C<-style =E 'image'> option,
specifies an image to use for the entire button when active.
=item B<-angle> C<=E> I
Optional shading angle for round or shiny style buttons (i.e., the position on the
button which is the brightest). Can be any fractional value between
0 and 1.0; values less than 0.01 may cause divide-by-zero errors. Default depends
=item B<-dispersion> C<=E> I
Optional fractional dispersion factor applied to the shading style for the button
(i.e., the amount of "spread" of bright areas).
Can be any fractional value between 0 and 1.0. Default is 0.80.
=item B<-idleimage> C<=E> I
When specified with the C<-style =E 'image'> option,
specifies an image to use for the entire button when idle.
=item B<-orient> C<=E> I<$orientation>
Optional orientation of the button. C<$orientation> may be any of
'n', 's', 'e', 'w', 'nw', 'ne', 'sw', 'se', 'wn', 'ws', 'en', 'es'.
Default is 'ne'. Intended for use with L, may not be
useful for general purposes.
=item B<-shape> C<=E> B<'rectangle'> C<| 'round' | 'oval' | 'bevel' | 'folio' | [ @coords ] >
Optional shape for the button. Default is rectangle. Note that bevel and
folio shapes are intended for L, and may not be
appropriate for general use. The shape is used both to render the buttons,
and to define the event binding area over the button images.
If the C<-style> is 'image', the application may supply its own set of
binding coordinates via an arrayref of polygon (X, Y) vertices, thereby
permitting arbitrary bounding areas for the button (e.g., triangle,
half circle, octagon, etc.) that match the appropriate edges of the
=item B<-style> C<=E> B<'shiny'> C<| 'round' | 'gel' | 'flat' | 'image'>
Optional shading style for the button. Default is shiny. C<'image'>
indicates that the C<-idleimage> and C<-activeimage> option values
should be used for the entire button, with the active area determined
by the C<-shape> option. This option is intended to optimize rendering
for static buttons.
=item B<-tooltip> C<=E> I<$text> B<|> I<[ $text, $delay ]>
Optional tooltip to be attached to the button. Causes a L
to be attached to the bidnign area of the button, using the supplied
C<$text> and C<$delay>. If a scalar is supplied, the default C<$delay>
is 300 milliseconds.
=item B<-usegd> C<=E> B<0> C< | 1>
Causes the button to be rendered as a single GD image embedded
in a Tk::Canvas, rather than a assembling the various components
into a Tk::Canvas. Primarily used for the C method.
Note that L and L are required to support this option.
=item B<-verticaltext> C<=E> B<'Tk'> C<| 'GD' | undef>
Causes the text of vertically oriented buttons to be drawn using the
specified method. This option is provided primarily for use
by L to render left and right side tabs. If set to 'GD',
the text is rendered as a GD image, then rotated 90 degrees before
being embedded in the button. If set to 'Tk' (the default), the text
is broken up so as to "stack" the characters vertically in the button,
and the text is then rendered using the normal Tk methods. If set
to C, then the text is rendered horizontally using Tk
(resulting in wide side tabs).
=head1 WIDGET METHODS
B is a subclass of L.
This widget supports the B and B methods
described in L which can be used to enquire and
modify the options described above.
The widget also inherits all the methods provided by the generic
=item (C<$active_image, $active_coords, $idle_image, $idle_coords>) = I<$button>-EB( I<%options> )
Captures the active and idle images and binding coordinates of the button in the
specified $format, as defined by the L module (default 'PNG'). Requires the
installation of L and L modules; also requires L
module for Win32 platforms.
C<$active_image> and C<$idle_image> are returned as scalars as output from the GD
rendering methods. C<$active_coords> and C<$idle_coords> are arrayrefs of the (X, Y)
polygon vertex coordinates used to create a transparent binding area on top of the images; active
and idle coordinates are usually the same, but both are provided for completeness.
Useful for later reusing static button images with the C<-style =E 'image'> option.
I<%options> may include:
=item B<-format> I<=E> C<$format>
Specifies the output format of the image; can be any of
'PNG', 'GIF', or 'JPEG'. Default is 'PNG'.
=item B<-omittext> I<=E boolean>
If set to a true value, any text assigned to the button will
be omitted from the rendered image. Useful for creating general
purpose buttons that can be overlaid with text later.
=item B<-omitimage> I<=E boolean>
If set to a true value, any image assigned to the button will
be omitted from the rendered button image. Useful for creating general
purpose buttons that can be overlaid with an image later.
If no image or text has been assigned to the button, then
the C<-height> and C values will be used to as the bounding box
for the button.
=item B<-gdfont> I<=E 'string' | \&coderef >
Specifies a GD-compatible font for any text to be included
in the captured image; ignored if no text has been applied to
the button, or the L<-omittext> option has been set true.
Perl/Tk font specifications are not
compatible with L, which only supports TrueType
fonts, or the internal GD default fonts. In addition, TrueType
fonts are specified to GD::Text as I, rather than
the X11 font formats usually supported by L.
In order to provide some means of translating between the
2 font systems, the B<-gdfont> option provides a means
to specify a GD::Text font. If the option value is a scalar,
it is passed directly to the L::set_font() method;
if it is a coderef, it will be called with the B<-family>,
B<-weight>, B<-slant>, and B<-size> options of the current
Tk::Font in use by the StyledButton, and should return
a list of (fontfile, size) that can be passed to GD::Text::set_font.
Note that the filename passed to GD::Text::set_font() must either
include absolute pathnames, or any of the GD::Text font environment
variables must be set (e.g., B).
Also note that Perl/Tk can support TrueType fonts, but may apply
internal modifications to render bold or italic versions; in such cases,
GD::Text may be unable render the same weight or slant.
Win32 platforms may omit this option if a TrueType font is being used
and its filename can be generated via L.
If the B<-gdfont> option is not specified and the font filename
cannot be resolved, then a default font is selected from the
GD internal font set, based on the size, weight, and slant
of the button's font.
Finally, note that Perl/Tk returns font sizes in pixels, rather than
points, and that GD::Text font specifications require a point, rather than
pixel, size. Therefore, this module selects the proper point size
to use by iterating over point sizes and computing the button text
size via GD::Text until the resulting width is the same (or neary same)
as the Perl/Tk computed width. This iteration may take some time
=item I<$button>-EB( [ I<$interval> ] )
Same as L::flash() method, except that an
optional interval parameter is supported.
If no C<$interval> is specified, the behavior is the same as
Tk::Button::flash(), i.e., 3 very quick flashes.
If C<$interval> is zero, then any current flash operation
If C<$interval> is non-zero, then the button rotates between
the bright and dark versions every $interval milliseconds,
until it is explicitly cancelled via C, or any
other mouse or keyboard initiated event is applied to the button.
Same as L method.
The following examples are in the C directory:
Simple script to display a single button. Button traits are
specified via command line parameters:
Simple script to flash a button.
A simple button "studio" with the ability to interactively set
various parameters for a button, and then capture the button images
bar, or for use with the C<-style =E 'image'>).
=item C<-underline> B
Due to the limits of Canvas text elements, support for
-underline is difficult, if not impossible.
=item C<-width> and C<-height> B
If no explicit width/height values are set, the width/height
of the button is determined by the -padx/-pady values, the
bounding box coordinates of any applied text, image, and/or bitmap,
and the -compound setting. If no text or image is applied,
the default width and height are 100 and 30, respectively.
If width or height is explicitly set, then the rendered button
shape will be constrained to those parameters, which may
result in scaling the button contents to fit within the
specified width or height.
Button contents are scaled as follows:
Either C<-width> and/or C<-height> have been explicitly set, and the
specified width/height is smaller than the bounding box computed from
the text, image, and bitmap, the C<-padx> and C<-pady> values, and
the C<-compound> value. In this case, the button is first rendered to
the computed size, then scaled to the explicitly specified dimensions.
When C<-style =E> I<'image'>, and the dimensions of the activeimage
and/or idleimage are smaller than the computed bounding box for
any supplied text/image/bitmap, the active/idle images are first
scaled up to fit the contents before the contents are supplied.
When C<-style =E> I<'image'>, and C<-width> and/or C<-height> have been
explicitly set, the active and idle images are first scaled to fit any
text/image/bitmap contents, and then the result is scaled up or down as needed
to fit the specified dimensions,
=item BI<$button>-Ecget(C<-width>, C<-height>)
When retrieving the C<-width> or C<-height> via C,
the returned value is the width/height of the enclosing
Canvas object, which is usually determined by the implicit
width/height computed from the defaults, or the applied
Tk::StyledButton overrides the default widget bind() method
in order to assure that any key or mouse events are bound to
the transparent binding element, rather than the entire
canvas. The following events are routed to the
Activate Deactivate MapRequest
Circulate Destroy Property
CirculateRequest Expose Reparent
Colormap FocusIn ResizeRequest
Configure FocusOut Unmap
ConfigureRequest Gravity Visibility
=item C BC<-bitmap>
GD doesn't provide an interface for rendering Tk's notion
of bitmaps; hence, L() will not include the C<-bitmap>
image in its rendered button.
=item C<-image> B C<-bitmap> B
A StyledButton may have either image or bitmap content, but not
both. If both are specified, image will take precendence (i.e.,
the bitmap will not be added).
Due to a bug win Perl/TK 804.027 on Win32, transparent stipples
do not work with oval items in canvases. In order to provide
a binding area for C<-shape =E 'round' | 'oval'>, a 12 sided
polygon is used instead, which leaves some small unbound
areas near the edges of the button. I<(oval buttons use the
polygon for the rounded endcaps)>.
=item B C<-style =E 'image'>
If the dimensions of the C<-activeimage> is different than the
dimensions of the C<-idleimage>, the bind area will be mapped to the
dimensions of the smaller image.
=head1 TO DO
=item BC<-style =E \&callback>
Like C<-shape =E \@vertices>, this option would permit
applications to provide their gradient styling, and leave the
mechanics of responding to various Button events to Tk::StyledButton.
Since the gradient computation is relatively isolated
internally, it should be feasible to expose an interface
which permits applications to supply their own gradient