Thread Linien und Group-boxen (8 answers)
Opened by theresa at 2008-02-26 12:21

MatthiasW
 2008-02-28 17:42
#106468 #106468
User since
2008-01-27
367 Artikel
BenutzerIn
[default_avatar]
Das Label brauchst du doch gar nicht um eine Linie zu malen, dafür reicht ja schon ein Frame:
Code: (dl )
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
#!/usr/bin/perl

use strict;
use warnings;

use Tk;

my $mw = tkinit();
$mw->geometry('200x200');

$mw->update;

for my $x ( 1 .. 50 )
{
my $y = sin($x)*100;
my $x1 = 100;
my $x2 = $x1 + $y;

($x1, $x2) = ($x2, $x1) if $x2 < $x1;

$mw -> draw_hl(
$x1,
$x*4,
$x2-$x1,
'darkblue',
);

$mw -> update;
} # for

MainLoop;

#
# draw an horizontal line using a Frame widget
#
sub Tk::Toplevel::draw_hl {
my( $mw, $x, $y, $w, $c ) = @_;

$mw -> Frame(
-width => $w,
-height => 1,
-bd => 0,
-background => $c,
) -> place(
-x => $x,
-y => $y,
);
} # draw_hl

__END__

Das Programm zeichnet eine Sinuskurve um 90° gedreht.
Die Funktion draw_hl() zeichnet dabei jeweils eine horizontale Linie.
Für eine vertikale Linie müssen die Werte von -width und -height nur vertauscht werden.
Für relative Höhen, Breiten und Koordinaten bieten sich natürlich andere geometry manager an.

MfG
perl -E'*==*",s;;%ENV=~m,..$,,$&+42;e,$==f;$"++for+ab..an;@"=qw,u t,,print+chr;sub f{split}say"@{=} me"'

View full thread Linien und Group-boxen