Perl 文本框中的行距丢失

Perl 文本框中的行距丢失,perl,hash,textbox,tk,Perl,Hash,Textbox,Tk,我一直在尝试编写一个perl脚本,它应该读取一个文件,解析它,显示内容的简要摘要(以特定模式开头和结尾的集合打印),并在用户选择某个集合的摘要时将其显示在报告区域中。我逐行读取文件,查找起始字符和结束字符,并将其与其他元数据一起保存在散列中,我使用这些元数据构建摘要。然后我尝试创建一个Textbox/ROText/Pane。但是,当我尝试使用insert命令填充全部内容时,数字之间的所有间距都丢失了。当我将相同的行打印到文件或屏幕上时,不会发生这种情况,间距是保留的。有人能解释一下为什么会在GU

我一直在尝试编写一个perl脚本,它应该读取一个文件,解析它,显示内容的简要摘要(以特定模式开头和结尾的集合打印),并在用户选择某个集合的摘要时将其显示在报告区域中。我逐行读取文件,查找起始字符和结束字符,并将其与其他元数据一起保存在散列中,我使用这些元数据构建摘要。然后我尝试创建一个Textbox/ROText/Pane。但是,当我尝试使用insert命令填充全部内容时,数字之间的所有间距都丢失了。当我将相同的行打印到文件或屏幕上时,不会发生这种情况,间距是保留的。有人能解释一下为什么会在GUI中发生这种情况吗?下面是我试图读取的文件的一个示例:

Assume that the file to be read looks as follows:

Starting report1
----------------------------------------
A B                   0.46    1.00  4.79
C                             2.00  8.54
DEF                   0.72          7.38
GH                            6.97  8.88
IJK                   7.46 8  6.98  4.32
End of report1


The GUI displays it randomly like this:

Starting report1
----------------------------------------
A B    0.46  1.00  4.79
C      2.00  8.54
DEF  0.72 7.38
GH     6.97 8.88
IJK   7.46 8  6.98  4.32
End of report1
代码如下:

my $summary_list = $summary_box->Scrolled("Listbox", -height => 5,-width => 120,-font => "7x13bold",-scrollbars => "ose", -exportselection => 1, -background => "black", -foreground => "white", -selectmode=>'single', -relief => 'groove')->pack(-side => 'left', -fill => "both", -expand =>1);
$summary_list->bind('<Button-1>', [\&retrieveReport] );

# Create the detailed text area, bind it to the summary list, configure the highlight text and disable editing
#my $report_area = $display_frame -> Frame()->pack(-side => 'top', -expand => 1, -fill =>'both');
my $report_area = $display_frame -> LabFrame(-label => 'Selected Path', -labelside => 'acrosstop')->pack(-side => 'top', -expand => 1, -fill =>'both');
my $report_entry = $report_area->Scrolled("ROText", -height => 30,-width => 120, -font => "5x5",-scrollbars => "se", -exportselection => 1, -wrap => "none")->pack(-fill => "both", -expand =>1);
$report_entry->tagConfigure( 'highlight', -background => 'lightgreen', -foreground => 'black', -font => "Arial 15 bold" );

sub retrieveReport {
my @sel = $summary_list->curselection;  
$report_entry->delete("0.0",'end');
$report_entry->insert('end',$display_paths{$sel[0]}{report});
#print "$display_paths{$sel[0]}{report}\n";

#Debug
my @lines = split("\n",$display_paths{$sel[0]}{report});
foreach (@lines) {
    #$report_entry->insert('end',$_);
    #$report_entry->insert('end',"\n");
    #print "$_\n";
}

# Highlight text
my @includes = $include_list->get(0, 'end');
foreach (@includes) {
    $_ =~ s/([\/\]\[])/\\$1/g;
    while ($display_paths{$sel[0]}{report} =~ /$_/gi) {
        $report_entry->tagAdd('highlight',"1.0 + $-[0] chars","1.0 + $+[0] chars");
    }
}
}
my$summary\u list=$summary\u box->滚动(“列表框”、-height=>5、-width=>120、-font=>“7x13bold”、-scrollbars=>“ose”、-exportselection=>1、-background=>“black”、-front=>“white”、-selectmode=>“single”、-relief=>“groove”)->-pack(-side=>“left”、-fill=>“tware”、-expand=>1);
$summary\u list->bind(“”,[\&retrieveReport]);
#创建详细文本区域,将其绑定到摘要列表,配置突出显示文本并禁用编辑
#我的$report\u区域=$display\u frame->frame()->pack(-side=>'top',-expand=>1,-fill=>'both');
my$report\u area=$display\u frame->LabFrame(-label=>'Selected Path',-labelside=>'acrosstop')->pack(-side=>'top',-expand=>1,-fill=>'both');
my$report\u entry=$report\u area->Scrolled(“ROText”、-height=>30、-width=>120、-font=>“5x5”、-scrollbars=>“se”、-exportselection=>1、-wrap=>“none”)->pack(-fill=>“两者”、-expand=>1);
$report_entry->tagConfigure('highlight',-background=>'lightgreen',-front=>'black',-font=>“Arial 15 bold”);
子检索端口{
my@sel=$summary_list->curselection;
$report_entry->delete(“0.0”,“end”);
$report_entry->insert('end',$display_路径{$sel[0]}{report});
#打印“$display_paths{$sel[0]}{report}\n”;
#调试
my@lines=split(“\n”,$display_path{$sel[0]}{report});
foreach(@行){
#$report\u entry->insert('end',$);
#$report\u entry->insert('end',“\n”);
#打印“$\u\n”;
}
#突出显示文本
my@includes=$include_list->get(0,'end');
foreach(@includes){
$\=~s/([\/\]\[])/\\$1/g;
while($display_paths{$sel[0]}{report}=~/$\ugi){
$report_entry->tagAdd('突出显示',“1.0+$-[0]字符”,“1.0+$+[0]字符”);
}
}
}

我认为是可变宽度字体破坏了间距。尝试删除所有字体选择TK已严重损坏。假设你找到了解决这个字体问题的方法,你很快就会发现tk还有很多其他问题(布局错误、文件句柄限制、缺少小部件、滚轮不工作等等)。如果你们不太深入,我建议使用Gtk(我最喜欢的)或Qt。你们是对的。删除字体配置并使用默认设置已固定间距。真奇怪。我不知道该怎么解决这个问题。我一定会看看Gtk。看起来不错。但我会看看是否能找到一个像样的解决办法。我的小部件已经完成,这是唯一困扰我的事情。Tk没有任何布局错误。滚轮很容易绑定到滚动区域。我无法理解为什么有人会使用任何没有Tk的grid和pack manager的图形包。