Thread Tk Basics: ein A.. voll variablen (12 answers)
Opened by FtR at 2004-08-07 17:09

Dubu
 2004-08-09 03:51
#42412 #42412
User since
2003-08-04
2145 Artikel
ModeratorIn + EditorIn

user image
Na gut, weil du es bist. ;)

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
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Data::Dumper;

# Test-HoH
my %HoH = (
   EbeneEinsText   => 'Text auf Ebene 1',
   EbeneEinsH      => {
       EbeneZweiZahl => 22,
       EbeneZweiH      => {
           EbeneDreiZahl       => 42,
           EbeneDreiText       => '3. Ebenentext',
       },
   },
   EbeneEinsText2   => 'Noch ein Text auf E1',
);

print Dumper \%HoH; # vorher
my $Mw = MainWindow->new();
hwids($Mw, \%HoH);
$Mw->Button(-text => 'Exit', -command => sub{ print Dumper \%HoH; # nachher
       Tk::exit() })->pack;
MainLoop;


sub hwids {
   my ($parent, $hashp) = @_;
   for (sort keys %$hashp) {
       if (ref $hashp->{$_}) {
           if (ref $hashp->{$_} eq 'HASH') {
               my $newframe = $parent->Frame (-borderwidth => 1, -relief => 'sunken')
                   ->pack(-padx => 20, -anchor => 'w');
               hwids($newframe, $hashp->{$_});
           } else {
               die "Bummer: Hash member $_ is a " . ref($hashp->{$_});
           }
       } else {
           $parent->Label (-text => $_)->pack(-anchor => 'w');
           $parent->Entry (-textvariable => \$hashp->{$_})->pack(-anchor => 'w');
       }
   }
}

View full thread Tk Basics: ein A.. voll variablen