Thread Anfrage an die FAQ: Grundsätzliches TK-Problem (13 answers)
Opened by JW at 2007-05-18 01:52

JW
 2007-05-18 01:52
#46325 #46325
User since
2003-08-04
467 Artikel
HausmeisterIn
[Homepage] [default_avatar]
Folgenden Anfrage kam per Mail an die FAQ-Abteilung. ;-) Da ich mit Tk kaum bis keinerlei Erfahrung habe, leite ich mal ins Forum weiter. E-Mail Adresse des Hilfsbedürftigen gibt es bei mir. Ich gebe ihm aber auch den Link diese Fred's.

JW


Hallo!

Ich finde eure Page wirklich sehr hilfreich, aber ich habe leider ein Problem, da ich bis Montag ein Perl/Tk-Beispiel zu programmieren habe und leider nicht weiter weiß.

Hier ist mein Programm, dass ich bis jetzt geschrieben habe und es funktioniert tadellos:

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
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl 

use strict;
use warnings;
use Tk;


# Hauptfenster
my $nw = MainWindow->new();

# Titel
$nw->title ('Man-Machine Interfaces II - UE - BSP 1');

# Menü
my $mb = $nw->Frame (-relief => 'ridge')->pack (-side => 'top', -fill => 'x');
my $m_file = $mb->Menubutton (-text => "File", -underline => 0)->pack (-side => 'left');
$m_file->command (-label => "Activate", -command => sub {activate()});
$m_file->separator();
$m_file->command (-label => "Quit", -command => [$nw => 'destroy']);

# Frames
my $f1 = $nw->Frame()->pack (-side => 'top', -expand => 1, -fill => 'both');
my $f2 = $nw->Frame()->pack (-side => 'bottom', -expand => 1, -fill => 'both');

# Radiobuttons
my $r1 = $f1->Frame (-borderwidth => 3, -relief => 'groove')->pack (-side => 'left', -expand => 1, -fill => 'both');
my @listenwahl = ('1', '2', '3');
my $liste = 0;
for my $a (0..$#listenwahl)
{
$r1->Radiobutton (-text => $listenwahl[$a], -variable => \$liste, -value => $a)->pack (-anchor => 'e');
}

my $r2 = $f1->Frame (-borderwidth => 3, -relief => 'groove')->pack (-side => 'left', -expand => 1, -fill => 'both');
my @textwahl = ('normal', 'rückwärts');
my $text = 0;
for my $b (0..$#textwahl)
{
$r2->Radiobutton (-text => $textwahl[$b], -variable => \$text, -value => $b)->pack (-anchor => 'w');
}

# Entries
my $entry1 = $nw->Entry (-text => "Das ist ein Satz!")->pack (-side => 'top');
my $entry2 = $nw->Entry (-text => "!ztaS nie tsi saD");

# Listboxen und Scrollbars
my $listbox1 = $f2->Listbox()->pack (-side => 'left', -expand => 1, -fill => 'both');
my $scrollbar1 = $f2->Scrollbar(-command, [yview => $listbox1])->pack (-side => 'left', -expand => 1, -fill => 'both');

my $listbox2 = $f2->Listbox()->pack (-side => 'left', -expand => 1, -fill => 'both');
my $scrollbar2 = $f2->Scrollbar(-command, [yview => $listbox2])->pack (-side => 'left', -expand => 1, -fill => 'both');

my $listbox3 = $f2->Listbox()->pack (-side => 'left', -expand => 1, -fill => 'both');
my $scrollbar3 = $f2->Scrollbar(-command, [yview => $listbox3])->pack (-side => 'left', -expand => 1, -fill => 'both');

MainLoop();


Wie man sieht, hab ich beim Menü anlegen "Activate" angelegt und darin subroutine "activate". Jetzt soll mit dieser subroutine folgendes passieren.

Die ersten 3 Radiobuttons geben an, welche Listbox ausgewählt wird und die anderen 2 geben an, die der Entry-Text in der jeweiligen Listbox angezeigt werden soll (entry2 soll als entry nicht angezeigt werden).

Wenn Radiobutton 1 und Radiobutton normal angeklickt sind, dann soll in der Listbox 1 der Text normal angezeigt werden. Wenn Radiobutton 1 und Radiobutton rückwärts angeklickt sind, dann soll in der Listbox 1 der Text rückwärts angezeigt werden (daher entry2). Für Radiobutton 2 & 3 und Listbox 2 & 3 gilt das Selbe.

Ich weiß, dass ich die Subroutine nach der MainLoop zu schreiben habe. Nur weiß ich leider nicht, wie ich die Radiobuttons miteinander so verknüpfen soll, so dass dann der Text, wenn man im Menü auf Activate klickt, richtig angezeigt wird (entweder normal oder rückwärts).

Ich bedanke mich schon mal im Voraus für die große Hilfe, die ihr mir geben könnt. Dann kann ich am kommenden Montag, das Beispiel ohne Probleme abgeben.

Einen schönen Feiertag.

LG, Robert!

View full thread Anfrage an die FAQ: Grundsätzliches TK-Problem