5 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
package Tk::CanvasG; require Tk::Frame; @ISA = qw(Tk::Frame); Construct Tk::Widget 'CanvasG'; use strict; use warnings 'all'; use vars qw($VERSION); $VERSION = '0.1.0'; use Data::Dumper; # # create the widget # sub Populate { my($frame, $args) = @_; # get widget specific options my $bg = delete $args->{-fieldbackground} || delete $args->{-background} || "black"; my $fg = delete $args->{-fieldforeground} || delete $args->{-foreground} || "lightgreen"; # Populate Frame $frame->SUPER::Populate($args); # create advertised widget: Canvas print Dumper($bg, $fg); my $canvas = $frame -> Canvas (-background => $bg)->pack (-fill => "both", -expand => 1); $frame -> Advertise ('canvas' => $canvas); # delegates to frame $frame -> Delegates (DEFAULT => $frame); # configure to canvas $frame -> ConfigSpecs ('-fieldbg' => '-fieldbackground', '-fieldfg' => '-fieldforeground', -fieldbackground => ["PASSIVE", "", "", "#000000"], -fieldforeground => ["PASSIVE", "", "", "#1fff1f"], DEFAULT => [$canvas]); } # Populate # return true 1; __END__
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
package Test;
use base qw(Tk::Frame);
use Tk::widgets qw(Canvas);
Construct Tk::Widget 'Test';
use strict;
use warnings 'all';
sub Populate
{
my($frame, $args) = @_;
# create Frame
$frame->SUPER::Populate($args);
# create Canvas
my $canvas = $frame->Canvas(-background => "black")->pack();
$frame->Advertise('canvas' => $canvas);
# delegates and configspecs
$frame->Delegates (DEFAULT => $frame);
$frame->ConfigSpecs(DEFAULT => [$canvas]);
return $frame;
} # Populate
package main;
use strict;
use warnings 'all';
use Tk;
my $mw = tkinit();
my $test = $mw->Test()->pack();
MainLoop;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
package Test;
use base qw(Tk::Derived Tk::Frame);
use Tk::widgets qw(Canvas);
Construct Tk::Widget 'Test';
use strict;
use warnings 'all';
sub Populate
{
my($frame, $args) = @_;
$args->{-background} = 'black' unless defined $args->{-background};
# create Frame
$frame->SUPER::Populate($args);
# create Canvas
my $canvas = $frame->Component(Canvas => 'canvas',)->pack();
# delegates and configspecs
$frame->Delegates (DEFAULT => $frame);
$frame->ConfigSpecs(DEFAULT => [$canvas]);
return $frame;
} # Populate
package main;
use strict;
use warnings 'all';
use Tk;
my $mw = tkinit();
my $test = $mw->Test()->pack();
MainLoop;
5 Einträge, 1 Seite |