Tk::ColoredButton - Button widget with background gradient color. |
Tk::ColoredButton - Button widget with background gradient color.
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::ColoredButton; my $mw = MainWindow->new( -background => 'white', -title => 'ColoredButton example' ); $mw->minsize( 300, 300 ); my $coloredbutton = $mw->ColoredButton( -text => 'ColoredButton1', -autofit => 1, -font => '{arial} 12 bold', -command => [ \&display, 'ColoredButton1' ], )->pack(qw/-padx 10 -pady 10 /); my $coloredbutton2 = $mw->ColoredButton( -text => 'ColoredButton2', -font => '{arial} 12 bold', -command => [ \&display, 'ColoredButton2' ], -height => 40, -width => 160, -gradient => { -start_color => '#FFFFFF', -end_color => '#BFD4E8', -type => 'mirror_vertical', -start => 50, -number_color => 10 }, -activegradient => { -start_color => '#BFD4E8', -end_color => '#FFFFFF', -type => 'mirror_vertical', -start => 50, -number_color => 10 }, -tooltip => 'my button message', )->pack(qw/-padx 10 -pady 10 /); $coloredbutton2->flash(); my $button = $mw->Button( -activebackground => 'yellow', -background => 'green', -text => 'Real Button', -font => '{arial} 12 bold', -command => [ \&display, 'Button' ], )->pack(qw/-ipadx 10 -pady 10 /); MainLoop; sub display { my $message = shift; if ($message) { print "$message\n"; } }
Tk::ColoredButton is an extension of the Tk::Canvas::GradientColor widget. It is an easy way to simulate a button widget with gradient background color.
The following the Tk::Button manpage options are supported :
-activebackground -activeforeground -anchor -background -bitmap -borderwidth -command -compound -cursor -disabledforeground -font -foreground -height -highlightbackground -highlightcolor -highlightthickness -image -justify -padx -pady -relief -repeatdelay -repeatinterval -state -takefocus -text -textvariable -width -wraplength
There are many options which allow you to configure your button as you want.
-activegradient => { -start_color => '#BFD4E8', -end_color => '#FFFFFF', -type => 'mirror_vertical', -start => 50, -number_color => 10 },
Default : { -start_color => '#FFFFFF', -end_color => '#B2B2B2' }
-autofit => 1,
Default : 0
-gradient => { -start_color => '#FFFFFF', -end_color => '#BFD4E8', -type => 'mirror_vertical', -start => 50, -number_color => 10 },
Default : { -start_color => '#B2B2B2', -end_color => '#FFFFFF' }
You can also use the autofit option if you want to have an automatic adjustment for your button.
Default : -height => 20, -width => 80,
-imagedisabled => $image_photo,
Default : undef
$iniwait Specifies the amount of time to wait without activity before popping up a help balloon. Specified in milliseconds. Defaults to 350 milliseconds. This applies to both the popped up balloon and the status bar message.
-tooltip => 'my button message', -tooltip => ['my button message', 200],
Default : undef
You can use invoke method like in the Tk::Button manpage.
$button_bgc->delete_tooltip;
$interval is the time in milliseconds between each alternative.
If $interval is not specified, the button will alternate between active and normal colors every 300 milliseconds.
If $interval is zero, any current flash operation will be cancel.
If $interval is non-zero, the button will alternate every $interval milliseconds until it is explicitly cancelled via $interval to zero or using cancel method to id returned.
my $id = $button_bgc->flash(1000); $button_bgc->flash(0); # Cancel the flash
$button_bgc->redraw_button;
Djibril Ousmanou, <djibel at cpan.org>
Please report any bugs or feature requests to bug-tk-coloredbutton at rt.cpan.org
, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
See also the Tk::StyledButton manpage and the Tk::Button manpage.
You can find documentation for this module with the perldoc command.
perldoc Tk::ColoredButton
You can also look for information at:
Copyright 2011 Djibril Ousmanou.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
Tk::ColoredButton - Button widget with background gradient color. |