Thread Tk - Radiobuttons mit grid (2 answers)
Opened by user123 at 2012-06-20 15:13

pktm
 2012-06-20 18:31
#159244 #159244
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Hallo user123,

du kannst natürlich auch mit Grid Radiobuttons in einer Schleife erzeugen. Der Clou dabei ist, die Koordinaten (Zeile, Spalte) durch die Schleife vorzugeben.

Geht es dir nur um diesen Teil hier?
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
my $auswahl1 = $frm_auswahl -> Radiobutton(-text=>"Auswahl1",  
-value=>"a1", -variable=>\$portal);
my $auswahl2 = $frm_auswahl -> Radiobutton(-text=>"Auswahl2",
-value=>"a2", -variable=>\$portal);
my $auswahl3 = $frm_auswahl -> Radiobutton(-text=>"Auswahl3",
-value=>"a3", -variable=>\$portal);
my $auswahl4 = $frm_auswahl -> Radiobutton(-text=>"Auswahl4",
-value=>"a4", -variable=>\$portal);

$auswahl1 -> grid(-row=>3,-column=>0, -sticky => "w");
$auswahl2 -> grid(-row=>4,-column=>0, -sticky => "w");
$auswahl3 -> grid(-row=>5,-column=>0, -sticky => "w");
$auswahl4 -> grid(-row=>6,-column=>0, -sticky => "w");


Das kannst du lösen, indem du die Radiobuttons in ein Array steckst und dann darüber iterierst.

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
my @alle_radio_btns = ();
$alle_radio_btns[0] = $frm_auswahl -> Radiobutton(-text=>"Auswahl1",
-value=>"a1", -variable=>\$portal);
$alle_radio_btns[1] = $frm_auswahl -> Radiobutton(-text=>"Auswahl2",
-value=>"a2", -variable=>\$portal);
$alle_radio_btns[2] = $frm_auswahl -> Radiobutton(-text=>"Auswahl3",
-value=>"a3", -variable=>\$portal);
$alle_radio_btns[3] = $frm_auswahl -> Radiobutton(-text=>"Auswahl4",
-value=>"a4", -variable=>\$portal);

# später, wenn sie mit grid positioniert werden:
# NB: beginne in Zeile 3
my $gridde_ab_zeile = 3;
for( my $zaehler = 0; $zaehler < scalar(@alle_radio_btns); $zaehler++ ) {
my $radiobtn = $alle_radio_btns[ $zaehler ]; # das ist ein aktueller Radio-Button
my $ziel_zeile = $gridde_ab_zeile + $zaehler; # hier wird die Zeile berechnet
$radiobtn->grid(-row => $ziel_zeile, -column => 0);
}


Natürlich kann man das auch alles kürzer oder ander schreiben. Mach es so, wie es dir gefällt.

Grüße,
pktm
http://www.intergastro-service.de (mein erstes CMS :) )

View full thread Tk - Radiobuttons mit grid