0

我必须准备一个 GUI,Perl/Tk 应该在其中调用批处理命令(路径硬编码的本地命令)和传递参数(这是用户选择的 .csv 文件)-当用户按下 GENERATE 按钮时-此处简化就像在记事本中打开 .csv 文件一样。有人能帮我吗 ?

use Tk;


my $my_MW=MainWindow->new();
$my_MW->title("Sample application");
$my_MW->geometry("350x180-500+500");
$my_MW->resizable( 'no', 'no' );

my $my_Button=$my_MW->Button(-text=>"Select CSV Input File",-command=> \&get_file);
$my_Button->pack(-side=>"top",-expand=>1,-anchor=>"w",-padx => 20,-pady => 20);

my $filepath=" .... ";

my $my_Entry=$my_MW->Entry(-textvariable=> \$filepath);
$my_Entry->pack(-side=>"top",-expand=>1,-anchor=>"w",-padx => 20,-pady => 0,-fill=>"x");

my $my_Button1=$my_MW->Button(-text=>"GENERATE",-width => 12,-command=>sub{\&gen_rslt()});
$my_Button1->pack(-side=>"left",-expand=>1,,-pady => 20);
$my_Button1->configure(-state => 'disabled');

my $my_Button2=$my_MW->Button(-text=>"RESET",-width => 12,-command=>sub{\&clear_field()});
$my_Button2->pack(-side=>"left",-expand=>1,,-pady => 20);

my $my_Button3=$my_MW->Button(-text=>"EXIT",-width => 12,-command=>sub{exit()});
$my_Button3->pack(-side=>"left",-expand=>1,,-pady => 20);

MainLoop();

sub gen_rslt{

#Call the batch file and pass the file path as an argument!  
#batch file to open the file in notepad 
}

sub clear_field{
$my_Entry->delete(0,'end');
$my_Entry->insert(0," .... ");

$my_Button1->configure(-state => 'disabled'); 
}

sub get_file 
{
    $my_Entry->delete(0,'end');
  my @types =
       (["comma seperated files", [qw/.csv/]],
        ["All files",        '*'],
       );

  $filepath = $my_MW->getOpenFile(-filetypes => \@types) or return();
  $my_Button1->configure(-state => 'normal');  
}
4

1 回答 1

0

使用system命令可以打开文件。例子是

system("notepad.exe myfile.txt");

或者你也可以使用如下

system(notepad.exe, $filepath);
于 2016-09-29T08:13:40.393 回答