Leser: 15
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 61 62
use strict; use warnings; use Tk; my $mw = new MainWindow; $mw->geometry("420x150"); my $input_frame = $mw->Frame()->pack(-fill => 'x'); my $output_frame = $mw->Frame()->pack(-fill => 'x'); my $process_frame = $mw->Frame()->pack(-fill => 'x'); $input_frame->Label(-text => ' Input: ')->pack(-side => 'left'); my $inputfile_entry = $input_frame->Entry(-width => 50)->pack(-side => 'left'); $input_frame->Button(-text => ' suchen ',-command => [\&getFile, 'INPUT', $mw, $inputfile_entry])->pack(-side => 'left'); $output_frame->Label(-text => ' Output:')->pack(-side => 'left'); my $outputfile_entry = $output_frame->Entry(-width => 50)->pack(-side => 'left'); $output_frame->Button(-text => ' definieren',-command => [\&getFile, 'OUTPUT', $mw, $outputfile_entry])->pack(-side => 'left'); my $listbox = $process_frame->Listbox(-height => 200)->pack(-fill => 'both'); my $scroll = $listbox->Scrollbar(-command => [ 'yview', $listbox ]); $listbox->configure(-yscrollcommand => [ 'set', $scroll ]);$scroll->pack(-side => 'right', -fill => 'y', ); $process_frame->Button(-text => 'Zeilennummerierung hinzufügen',-command => [\&addLinenumbers, $mw, $inputfile_entry, $listbox])->pack(-side => 'left'); $process_frame->Button(-text => 'Schreibe Ausgabedatei',-command => [\&writeFile, $mw, $outputfile_entry, $listbox])->pack(-side => 'left'); $process_frame->Button(-text => 'Script beenden',-command => sub { exit })->pack(-side => 'left'); MainLoop(); my @types = (["Textdatei", ['.txt']]); sub getFile { my($action, $datAuswahl, $entry) = @_; my($filename)=""; #my $filetypes = [ ['Textfiles', ['.txt'] ] ]; if($action eq 'INPUT') { $filename = $datAuswahl->getOpenFile(-filetypes => \@types, -defaultextension => '.txt',-title => 'Select inputfile...'); } elsif($action eq 'OUTPUT') { $filename = $datAuswahl->getSaveFile(-filetypes => \@types, -defaultextension => '.txt',-title => 'Select outputfile...'); } else { warn "getFile(), no action specified!\n"; } if($filename ne '') { $entry->delete(0, 'end'); $entry->insert(0, $filename); } } ....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sub getFile { my($action, $datAuswahl, $entry) = @_; my($filename)=""; my $filetypes = [ ['Textfiles', '.txt' ], ['Textfiles', '.TXT'] ]; if($action eq 'INPUT') { $filename = $datAuswahl->getOpenFile( -filetypes => $filetypes, -title => 'Select a file...', ); }