Tk::Can...entColor(3)
πΈ NAME πΈ
okay bestie, welcome to the Tk::Can...entColor(3) page from User Contributed Perl Documentation β it's the manual for Tk::Canvas::GradientColor, and it's literally here to create a Canvas widget with background gradient color. β¨
β¨ SYNOPSIS β¨
here's the whole vibe in code, no edits:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Canvas::GradientColor;
my $mw = MainWindow->new(
-title => 'Tk::Canvas::GradientColor',
-background => 'white',
);
my $canvas = $mw->GradientColor(
-width => 400,
-height => 400,
)->pack(qw/ -fill both -expand 1 /);
$mw->update;
sleep 3;
# Change color
$canvas->set_gradientcolor(
-start_color => '#000000',
-end_color => '#00CDFF',
);
$mw->update;
sleep 3;
# Change type
$canvas->set_gradientcolor(
-start => 50,
-end => 100,
-type => 'mirror_vertical'
);
MainLoop();
π DESCRIPTION π
Tk::Canvas::GradientColor is an extension of the Canvas widget. It is an easy way to build a canvas widget with gradient background color. basically: canvas, but make it gradient. π
π STANDARD OPTIONS π
these standard Canvas options are all in the mix, bestie:
-background-borderwidth-closeenough-confine-cursor-height-highlightbackground-highlightcolor-highlightthickness-insertbackground-insertborderwidth-insertofftime-insertontime-insertwidth-relief-scrollregion-selectbackground-selectborderwidth-selectforeground-takefocus-width-xscrollcommand-xscrollincrement-yscrollcommand-yscrollincrement
π¦ WIDGET-SPECIFIC METHODS π¦
The Canvas method creates a widget object. This object supports the configure and cget methods described in Tk::options β those are the ones you use to enquire about and modify the options described above. π«Ά
π disabled_gradientcolor π
$canvas_bg->disabled_gradientcolor
Disabled background gradient color. The canvas widget will have the background color set by -background option. no gradient, just background, periodt.
$canvas_bg->disabled_gradientcolor;
π enabled_gradientcolor π
$canvas_bg->enabled_gradientcolor
Enabled background gradient color. Background gradient color is activated by default. Use this method if disabled_gradientcolor method is called. it's the "bring the gradient back" button. β¨
$canvas_bg->enabled_gradientcolor;
π get_gradientcolor π
$canvas_bg->get_gradientcolor
Return a hash reference which contains the options to create the background gradient color.
my $ref_gradient_options = $canvas_bg->get_gradientcolor;
π set_gradientcolor π
$canvas_bg->set_gradientcolor(?options)
-typeβ 8 types are available :linear_horizontal,linear_vertical,mirror_horizontal,mirror_vertical,radial,losange,corner_rightandcorner_left.
-type => 'corner_left',
Default : linear_horizontal
-start_colorβ First color of gradient color.
-start_color => 'red',
Default : #8BC2F5
-end_colorβ Last color of gradient color.
-end_color => '#FFCD9F',
Default : white
-startβ
-start => 50, # Must be >= 0, <= 100 and start < end
- Use it for
linear_horizontalandlinear_verticaltype. The first color starts at 'start' percent width of canvas. The easy way to understand is to test the example in this documentation.
Ex : width canvas = 1000px, start = 50 : the first part of canvas has the background color of start_color and the gradient color start at 500px.
Default : 0
- Use it for
mirror_horizontalandmirror_verticaltype. The first color starts at 'start' percent width of canvas. The easy way to understand is to test the example in this documentation.
Ex : width canvas = 1000px, start = 50 : the background gradient color begins at 50 percent in two directions.
Default : 50
-endβ
-end => 80, # Must be >= 0, <= 100 and end > start
- Use it for
linear_horizontalandlinear_verticaltype. The last color finishes at 'end' percent width of canvas. The easy way to understand is to test the example in this documentation.
Default : 100
- Use it for
mirror_horizontalandmirror_verticaltype. The last color finishes at 'end' percent width of canvas and opposite. The easy way to understand is to test the example in this documentation.
Default : 100
-number_colorβ Number of colors between first and last color to create the gradient.
-number_color => 200,
Default : 100
π rgb_to_hex π
$canvas_bg->rgb_to_hex($red, $green, $blue)
Return hexa code of rgb color.
my $color = $canvas_bg->rgb_to_hex(200, 102, 65); # return #C86641
π hex_to_rgb π
$canvas_bg->hex_to_rgb(string)
Return an array with red, green an blue code rgb color.
my ( $red, $green, $blue ) = $canvas_bg->hex_to_rgb('#C86641'); # return 200, 102, 65
my ( $red, $green, $blue ) = $canvas_bg->hex_to_rgb('gray'); # return 190, 190, 190
π EXAMPLES π
An example to test the configuration of the widget:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Canvas::GradientColor;
use Tk::BrowseEntry;
my $mw = MainWindow->new(
-title => 'gradient color with canvas',
-background => 'snow',
);
my $canvas = $mw->GradientColor(
-background => '#005500',
-width => 500,
-height => 500,
)->pack(qw/ -fill both -expand 1 /);
my %arg_gradient = (
-type => undef,
-start_color => '#A780C1',
-end_color => 'white',
-start => undef,
-end => undef,
-number_color => undef,
);
# configure start color
my $bouton_color1 = $canvas->Button(
-text => 'select color start',
-command => sub {
$arg_gradient{-start_color} = $canvas->chooseColor( -title => 'select color start' );
$canvas->set_gradientcolor(%arg_gradient);
},
);
# configure end color
my $bouton_color2 = $canvas->Button(
-text => 'select color end',
-command => sub {
$arg_gradient{-end_color} = $canvas->chooseColor( -title => 'select color end' );
$canvas->set_gradientcolor(%arg_gradient);
},
);
my $type = $canvas->BrowseEntry(
-label => 'Type gradient color',
-choices => [
qw/ linear_horizontal linear_vertical mirror_horizontal mirror_vertical radial losange corner_right corner_left/
],
-background => 'white',
-state => 'readonly',
-disabledbackground => 'yellow',
-browsecmd => sub {
my ( $widget, $selection ) = @_;
$arg_gradient{-type} = $selection;
$canvas->set_gradientcolor(%arg_gradient);
},
);
my $start_num = $canvas->Scale(
-background => 'white',
-label => 'Start',
-from => 0,
-to => 100,
-variable => 0,
-orient => 'horizontal',
-sliderlength => 10,
-command => sub {
my $selection = shift;
$arg_gradient{-start} = $selection;
$canvas->set_gradientcolor(%arg_gradient);
},
);
my $end_num = $canvas->Scale(
-background => 'white',
-label => 'End',
-from => 0,
-to => 100,
-variable => '100',
-orient => 'horizontal',
-sliderlength => 10,
-command => sub {
my $selection = shift;
$arg_gradient{-end} = $selection;
$canvas->set_gradientcolor(%arg_gradient);
},
);
my $num = 100;
my $entry_number_color = $canvas->BrowseEntry(
-label => 'Number color',
-choices => [qw/ 2 3 4 5 10 50 100 150 200 250 300 400 500 750 1000 1500 2000 2500/],
-state => 'readonly',
-disabledbackground => 'yellow',
-background => 'white',
-variable => \$num,
-browsecmd => sub {
my ( $widget, $selection ) = @_;
$arg_gradient{-number_color} = $selection;
$canvas->set_gradientcolor(%arg_gradient);
},
);
my $disabled_gradientcolor = $canvas->Button(
-text => 'disabled_gradientcolor',
-command => sub { $canvas->disabled_gradientcolor; },
);
my $enabled_gradientcolor = $canvas->Button(
-text => 'enabled_gradientcolor',
-command => sub { $canvas->enabled_gradientcolor; },
);
$canvas->createWindow( 100, 100, -window => $bouton_color1 );
$canvas->createWindow( 400, 100, -window => $bouton_color2 );
$canvas->createWindow( 100, 150, -window => $start_num );
$canvas->createWindow( 100, 200, -window => $end_num );
$canvas->createWindow( 350, 150, -window => $entry_number_color );
$canvas->createWindow( 350, 200, -window => $type );
$canvas->createWindow( 100, 350, -window => $disabled_gradientcolor );
$canvas->createWindow( 400, 350, -window => $enabled_gradientcolor );
MainLoop;
π AUTHOR π
Djibril Ousmanou, "<djibel at cpan.org>"
π BUGS π
Please report any bugs or feature requests to bug-Tk-Canvas-GradientColor at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-Canvas-GradientColor>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. bestie, the pipeline is literally: you report, I get notified, you get notified. π«Ά
π₯ SEE ALSO π₯
See Tk::Canvas for details of the standard options.
πΈ SUPPORT πΈ
You can find documentation for this module with the perldoc command.
perldoc Tk::Canvas::GradientColor
You can also look for information at:
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-Canvas-GradientColor>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Tk-Canvas-GradientColor>
- CPAN Ratings
<http://cpanratings.perl.org/d/Tk-Canvas-GradientColor>
- Search CPAN
<http://search.cpan.org/dist/Tk-Canvas-GradientColor/>
π ACKNOWLEDGEMENTS π
This section is literally empty in the original β no acknowledgements listed. π
π COPYRIGHT & LICENSE π
Copyright 2014 Djibril Ousmanou, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π That's the whole page, bestie! Source/version and date from the footer: perl v5.32.1, 2024-09-23, on the Tk::Can...entColor(3) page. Byeee! π
π¦ where this page comes from
- epel 9: perl-Tk-Canvas-GradientColor 1.06-32.el9 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms