#!/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 @listboxes; my $liste = 0; my $m_file = $mb->Menubutton (-text => "File", -underline => 0)->pack (-side => 'left'); $m_file->command (-label => "Activate", -command => sub {activate($liste,\@listboxes)}); $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'); 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 => $textwahl[$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"); for (0..2) { push(@listboxes, $f2->Listbox()->pack (-side => 'left', -expand => 1, -fill => 'both')); $f2->Scrollbar(-command, [yview => $listboxes[$_]])->pack (-side => 'left', -expand => 1, -fill => 'both'); } MainLoop(); sub activate { my ($liste, $listbox_ref) = @_; print "$liste\n"; print join("\n", @$listbox_ref)."\n"; my $string = $entry1->get(); my @string = reverse split//,$string; $string = reverse($string) if ($text eq 'rückwärts'); @$listbox_ref[$liste]->insert('0.0', $string); }