Thread Automatische Button-Erzeugung: Funktioniert nicht so richtig (3 answers)
Opened by #Kein Kommentar at 2007-06-17 22:13

#Kein Kommentar
 2007-06-17 22:13
#46515 #46515
User since
2007-06-09
575 Artikel
HausmeisterIn
[default_avatar]
hi,

ich habe ein script geschrieben, mit dem eine tabelle angelegt wird, in der buttons erzeugt werden. wenn man auf einen button klickt, soll die command-funktion ausgeben welchen button man gedückt hat. vielleicht wird alles durch ein beispiel klarer:

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
use Tk; 
use Tk::Table;

##Variablen:
@ressorts = sort ("Wurst      ", "Brot       ", "Getränke   ", "Bio        ", "Kleidung   ", "Sonstiges  ", "Bus & Bahn ");
@DATE_DAYS_NAME = qw(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag);

##Hauptfenster:

$mw = MainWindow-> new (-title => "Testbeispiel");

##Tabelle:

$table_woche = $mw-> Table (-columns => 8, -rows => 8, -relief  => 'raised', -scrollbars => 0);

foreach $index (0..6) {
$widgets_label[$index] = $mw-> Label (-text => $DATE_DAYS_NAME[$index], -font => "Arial 11 bold underline");
$table_woche-> put (1,$index+1, $widgets_label[$index]);
$widgets_label[$index] = $mw-> Label (-text => $ressorts[$index], -font => "Courier 11 bold", -justify => left);
$table_woche-> put ($index+2,0, $widgets_label[$index]);

#Buttons mit den Ausgaben
foreach $zeile (0..6) {
$widgets_button{"$DATE_DAYS_NAME[$index]_$ressorts[$zeile]"} = $table_woche-> Button (-textvariable => \$ressorts[$zeile],
-width => 10, -relief => 'sunken', -justify => left, -command => sub {print "$ressorts[$zeile], $DATE_DAYS_NAME[$index]\n";});
$widgets_button{"$DATE_DAYS_NAME[$index]_$ressorts[$zeile]"}-> configure (-activebackground => blue);
$table_woche-> put ($zeile+2,$index+1, $widgets_button{"$DATE_DAYS_NAME[$index]_$ressorts[$zeile]"});
}
}

$table_woche->pack (-side => left);

MainLoop;


nur erscheint jetzt jedesmal egal welchen button man gedrückt
hat "Bio, Sonntag", anstatt den wirklichen standort anzuzeigen.

weiß jemand warum?
Gerade weil wir alle in einem Boot sitzen, sollten wir froh sein, dass nicht alle auf unserer Seite sind

View full thread Automatische Button-Erzeugung: Funktioniert nicht so richtig