Tk::Can...entColor(3)

πŸ“¦
version 1.06 Β· 4 versions
, in epel 9

🌸 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_right and corner_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_horizontal and linear_vertical type. 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_horizontal and mirror_vertical type. 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_horizontal and linear_vertical type. 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_horizontal and mirror_vertical type. 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 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