Thread 10 Buttons, 4 Reihen, 1 Schleife (7 answers)
Opened by Corey at 2009-01-25 20:38

Crian
 2009-01-26 13:00
#118334 #118334
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
Wie wäre es hiermit?

Code (perl): (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl

#------------------------------------------------------------------------------
# Pakete / Pragmas:
#------------------------------------------------------------------------------
use strict;
use warnings;

use Tk;

#------------------------------------------------------------------------------
# Mainwindow:
#------------------------------------------------------------------------------
my $mw = new MainWindow;

#------------------------------------------------------------------------------
# Buttonanordnung:
#------------------------------------------------------------------------------
my @textarray = (
    [qw/1 2 3/],
    [qw/4 5 6/],
    [qw/7 8 9/],
    [qw/0/]
);

#------------------------------------------------------------------------------
# Frames:
#------------------------------------------------------------------------------
my $f = $mw->Frame(
)->pack(
    -fill   => 'both',
    -expand => 1,
    -side   => 'top',
);
my @frames;
for (1 .. @textarray) {
    my $fx = $f->Frame(
    )->pack(
        -fill   => 'both',
        -expand => 1,
        -side   => 'top',
    );
    push @frames, $fx;
}

#------------------------------------------------------------------------------
# Buttons:
#------------------------------------------------------------------------------
my $frame_index = 0;
for my $texte (@textarray) {
    for my $text (@$texte) {
        my $b = $frames[$frame_index]->Button(
            -text    => "$text",
            -command => sub { print "Button '$text' wurde gedrueckt.\n" },
        )
        ->pack(
            -fill   => 'x',
            -ipadx  => 5,
            -side   => 'left',
            -fill   => 'both',
            -expand => 1,
        );
    }
    ++$frame_index;
}

MainLoop();



Das geht sicher kürzer / eleganter, aber irgendwas muss dir ja auch noch bleiben.
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite

View full thread 10 Buttons, 4 Reihen, 1 Schleife