merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I want to give the user a message in a failure condition.
The Tk DialogBox widget seems fine since you can ‘add’ what elements you want
and the resulting dialog is in ‘control’ until the user selects the Ok button
Adding a label is fine with the following code
$mw_text->add('Label', -text => $label_str)->pack;
I want to display a list in the dialog that varies in length. I thought I would
create this list in a variable with a line feed after each item as shown next
foreach $text_item (@$ref_text_array) { chomp($text_item); $text_str .= $text_item . "\n"; }
I want to show the list in a text box of the dialog box. I tried the following
$mw_text->add('Text', -scrollbars => "e", -width => 80, -height => 35, -text => $text_str )->pack();
However this failed.
It did not like –scrollbars (but I wanted them in case the list got too long)
It did not like –text (and –textvariable)
I have tried to find suitable examples on the internet but this failed!
What should I do?

Replies are listed 'Best First'.
Re: Adding 'text' to a Tk DialogBox
by thundergnat (Deacon) on Feb 12, 2008 at 18:18 UTC

    You probably don't want to use a Text widget since you most likely won't want an editable dialog box... and even a ROText seems like overkill. Probably just using a Label is your best bet. Pack it inside a scrolled Pane to get the scroll bars. See example.

    #!/user/bin/perl use strict; use warnings; use Tk; use Tk::DialogBox; use Tk::Pane; my $mw = MainWindow->new(); my $dialog = $mw->DialogBox( -title => "Title", -buttons => [ "OK", "Cancel" ] ); my $text_str = "blah\n" x 40; my $scrolled = $dialog->add( 'Scrolled', 'Pane', -scrollbars => 'osoe' +, )->pack; my $dtext = $scrolled->Label( -text => $text_str )->pack; my $reply = $dialog->Show; print "$reply\n"; MainLoop;
      That did exactly what I wanted to achieve!
      Many thanks