2017-02-14 50 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

相關問題