2017-02-14 59 views
0

我创建了一个包含“Key”列,“Value”列和“New Value”列的表格,如下图所示。 “键”和“值”列是作为标签实现的,“价值”列被包装,你可以看到。 “新值”列作为Entry小部件实现,因为它应该是可编辑的。有一个复制粘贴按钮,将该值复制到“新值”输入字段。 我想将文本包装在Entry小部件中,因此按下按钮后,它将看起来像“Value”字段中的文本。Perl TK - 将文本包装到条目窗口小部件中

Image that shows the table I built and the difference between the wrapped Label to the text in the Entry field

这里是一段代码定义所示的列:

 my $key_label = $table->Label(-text => $key , -width => 50, -bg => $background_color, -anchor => 'w', -relief => $relief_style, -wraplength => 300)->pack(-side => 'left'); 
     $table->put($curr_row,1,$key_label); 
     my $orig_val_label = $table->Label(-text => $full_cfg_hash{$key}{'old_value'}, -width => 50, -bg => $background_color, -anchor => 'w', -relief => $relief_style, -wraplength => 300)->pack(-side => 'left'); 
     $table->put($curr_row,2,$orig_val_label); 
     my $new_val_entry = $table->Entry(-text => $full_cfg_hash{$key}{'new_value'}, -width => $entry_size, -bg => $background_color)->pack(-side => 'left', -fill => 'both', -expand => 'yes'); 
     $table->put($curr_row,3,$new_val_entry); 
     my $copy_paste_btn = $table->Button(-text => "Copy & Edit\nOld Value", -command => [\&copy_n_edit_old_value,$full_cfg_hash{$key}{'old_value'},$new_val_entry], -bg => $buttons_background, -foreground => $buttons_text_color)->pack(-side => 'left', -padx => 5); 
     $table->put($curr_row,4,$copy_paste_btn); 

回答

0

Tk的::文本插件为多行文本输入,通常与Tk的组合: :滚动,类似于:

my $new_val_entry = $table->Scrolled(
    'Text', 
    -width  => 40, 
    -height  => 3, 
    -wrap  => 'word', 
    -scrollbars => 'e', 
    -font  => $my_font, 
)->pack(
    -expand => 1, 
    -fill => 'both', 
    -padx => 5, 
    -pady => 5, 
); 
+0

谢谢Stefan!使用Tk :: Text解决了这个问题。 – Eliad1983

相关问题