#!/usr/bin/perl use strict; use warnings; use Tk; my $main = MainWindow->new(); $main->Label(-text => 'Bitte machen Sie eine Eingabe: ', ) ->pack(-side => 'top', -anchor => 'w', ); my $eingabe= $main->Entry(-background => 'white') ->pack(-side => 'top' ); $main->Label(-text => ' ', ) ->pack(-side => 'top', ); $main->Button(-text => 'Speichern', -command => \&save, ) ->pack(-side => 'left', ); $main->Label(-text => ' ', ) ->pack(-side => 'left', ); $main->Button(-text => 'Speicher lesen', -command => \&read_saved, ) ->pack(-side => 'left', ); MainLoop(); sub save { my $top1 = $main->Toplevel(); open(FH, '>', 'test.txt') or die; print FH $eingabe->get(); close(FH); $top1->Label(-text => 'Ihre Eingabe wurde gespeichert! ' , ) ->pack(-side => 'top' ); $top1->Button(-text => 'OK', -command => [ $top1 => 'destroy' ], ) ->pack(-side => 'bottom', -fill => 'both', ); $eingabe->delete(0, 'end'); } sub read_saved { my $top1 = $main->Toplevel(); open(FH, '<', 'test.txt') or die; my @eingabe = ; close(FH); $top1->Label(-text => 'Ihre letzte Eingabe war:' ."\n" .$eingabe[0], ) ->pack(-side => 'top' ); $top1->Button(-text => 'OK', -command => [ $top1 => 'destroy' ], ) ->pack(-side => 'bottom', -fill => 'both', ); $eingabe->delete(0, 'end'); }