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

user123
 2012-06-20 15:13
#159235 #159235
User since
2010-10-12
21 Artikel
BenutzerIn
[default_avatar]
Hallo zusammen,

ich beschäftige mich derzeit mit Tk und versuche mit grid Radiobuttons aus einem Array zu erzeugen. Dies hatte ich bei pack auch ohne Probleme hinbekommen, dort habe ich dann aber meine GUI nicht hinbekommen.

Wie kann ich das am besten mit einer Schleife hinbekommen? Muss ich dann im unteren Teil des Codes noch mal eine Schleife durchlaufen lassen oder kann ich vielleicht am Anfang gleich eine Variable mit dem kompletten Inhalt erzeugen.

Ich hab mal den Code mit eingefügt. Es geht um das Frame $frm_auswahl.
Sorry wenn der Quelltext vielleicht etwas durcheinander ist, habe mir das irgendwie zusammengepfriemelt.

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
#!/usr/bin/perl -w

use Tk;
use Tk::BrowseEntry;

my $mw = new MainWindow;

$mw->title ("Test-GUI");

my $label1 = $mw->Label (-text=>"Test-Gui", -font => [-size => 12, -weight => "bold"]);
my $label2 = $mw->Label (-text=>"Auswahl", -height=>3, -font => [-size => 10, -weight => "bold"]);
my $label3 = $mw->Label (-text=>"Browse", -font => [-size => 10, -weight => "bold"]);
my $brows = "Alle";


my @radiobuttons      = (
                          'Auswahl1',
                          'Auswahl2',
                          'Auswahl3',
                          'Auswahl4',
                   );
my $radio_input = 0;

my $frm_auswahl = $mw -> Frame();

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);
my $browse = $mw->BrowseEntry(-variable => \$brows);            

my $button1= $mw->Button(-text=>"Beenden", -width => 20, -height => 2,-command=>\&cmd_button);
my $button2= $mw->Button(-text=>"Weiter", -width => 20, -height => 2);
my $button3= $mw->Button(-text=>"Editor", -width => 10, -height => 1);
 
$label1->grid (-row=>0, -column=>0, -columnspan=>6);
$label2->grid (-row=>2, -column=>0, -columnspan=>2, -sticky => "w");
$label3->grid (-row=>2, -column=>2, -columnspan=>2);

$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");
$frm_auswahl -> grid(-row=>3,-column=>0, -columnspan=>2, -sticky => "w");
$browse  -> grid(-row=>3,-column=>2, -columnspan=>2, -sticky => "n");

$button1->grid(-row=>7, -column=>0, -columnspan=>2, -sticky=>"w");
$button2->grid(-row=>7, -column=>4, -columnspan=>2, -sticky=>"e");
$button3->grid(-row=>3, -column=>4, -columnspan=>2, -sticky => "n");
 
sub cmd_button
{
   $mw->messageBox (-message=>"Progamm wird beendet!");
   exit;
}
MainLoop;

Last edited: 2012-06-20 15:16:08 +0200 (CEST)

View full thread Tk - Radiobuttons mit grid