#!/usr/bin/perl use Tk; use Tie::File; my $liste; my $liste_font; my $breite=100; my $the_selectmode = "extended"; my $enter; my @array_file; my $mw = MainWindow->new(); my $frame1 = $mw->Frame( -width=>50, -height=>50, -bg=>"seashell" ); my $frame2 = $mw->Frame( -width=>5, -height=>5, -bg=>"grey80" ); $liste_font = $mw->fontCreate(-family=>"courier", -size=>7 ); my $liste = $frame1->ScrlListbox( -setgrid=>1, -scrollbars=>"se", -background=>"lemonchiffon3", -borderwidth=>3, -highlightthickness=>10, -height => 30, -selectforeground=>"blue", -selectbackground=>"green", -relief=>"ridge", -exportselection => 1 )->pack(-side=>"right", -expand=>1, -fill=>"both"); my $exitButton = $frame2->Button( -text=>"Schliessen" ,- command=>"exit" , -bg=>"red" , -activebackground=>"red", -activeforeground=>"cyan" )->pack( -anchor=>"w", -padx=>10 , -pady=>15 , -ipady=>10, -fill=>"x" ); $frame1->pack(-side => 'left' ,-expand=>1 ,-fill=>"both"); $frame2->pack(-side => 'right',-expand=>1 ); $frame2->pack(-expand=>1 ,-fill=>"both"); $mw->repeat(10, \&fill_with_tie ); MainLoop; sub fill_from_file { my $file = "meinfile.txt"; my $line; $liste->delete(0,"end"); if ( -s $file ) { open(DATEI, "<$file") or die $!; while ($line = ) { chomp $line; $liste->insert(0,$line); } close(DATEI); } } sub fill_with_tie { my $file = "meinfile.txt"; my $line; my $elem; $liste->delete(0,"end"); if ( -e $file ) { tie @array_file, "Tie::File", $file || die $!; foreach $elem (@array_file) { chomp $elem; $liste->insert(0,$elem); } untie @array_file; } else { print "Kann $file nicht oeffnen $!\n"; } }