我创建了一个包含“Key”列,“Value”列和“New Value”列的表,如下图所示。 “密钥”和“值”列实现为标签,“值”列包装如您所见。 “新值”列实现为Entry小部件,因为它应该是可编辑的。有一个副本&粘贴按钮,将值复制到“新值”输入字段。 我想将文本包装在Entry小部件中,因此在按下按钮后,它将看起来像“Value”字段中的文本。
以下是定义所显示列的代码:
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 => [\©_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 :(得分:0)
Tk :: Text 小部件用于多行文本输入,通常与 Tk :: Scrolled 结合使用,如:
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,
);