2014-05-06 89 views
0

如何將打印輸出發送到perl/tk列表框,可以有無限制的打印行。 我知道如何創建列表框,但現在不要如何調用列表框並打印到它。 這是逐行生成打印的代碼。perl如何打印到perl/tk listbox

[code] 
    #!/usr/bin/perl -w 
    use strict; 

    #Read input file a line at a time 

     $mydelimiter=","; 



     open (INPUT1,"$INFILE1") or 
     die " cannot open $INFILE1"; 

     while (<INPUT1>) { 
    @INFILE = ($_); 
    chomp($_); 
    @FAILS = split (/,/,); 
    @SERVER = splice (@FAILS,0,1); 
    @TYPE = splice (@FAILS,0,1); 
    @REASON = splice (@FAILS,0,1); 
    @STATUS = splice (@FAILS,0,1); 
    @TICKET = splice (@FAILS,0,1); 
    @RESOLUTION = splice (@FAILS,0,1); 
    foreach $server1 (@SERVER) { 
     $servers = $server1; 
     $servers =~ tr/[a-z]/[A-Z]/; 
    } 

    foreach $type1 (@TYPE) { 
     $types = $type1; 
     $types =~ tr/[a-z]/[A-Z]/; 
    } 

    if ("$types" eq "F") { 
    $types="FAILED"; 
    } 
    else { 
    if ("$types" eq "S") { 
    $types="FILES"; 
    @TICKET="TICKET"; 
    }} 

    $value= &read_location; 
    if ("$value" ne "0"){ 
    print "@SERVER \n"; 
    } 
     [code] 

回答

0

下面是使用列表框

#!/usr/bin/perl 

use strict; 
use warnings; 
use Tk; 


my $win = new MainWindow; 
$win->geometry("400x300"); 

my $listbox = $win->Scrolled("Listbox", -scrollbars => 'se') 
->pack(-expand => 1, -fill => 'both'); 

my @array = qw/hello there world/; 
$listbox->insert('end', @array); 

#or 
for(@array){ 
    $listbox->insert('end', $_); #for single elements, note it appends to the listbox 
} 
MainLoop; 

這裏是繼續研究和信息的好資源使用例如Perl/Tk的腳本的Perl/TK

http://docstore.mik.ua/orelly/perl3/tk/index.htm