#!/usr/bin/perl -w
# This program shows how to create a customized dialog box.

# see also http://www.bitd.clrc.ac.uk/Publications/Cookbook/msg.html
# and "waitWindow" in the Tk::Widget man page

use Tk;
use strict;

my ($main);

sub form {
    my ($title, @field) = @_;
    my ($d, $i, $l, $e, $ans);
    $d = $main->Toplevel(-title=>$title);
    for ($i=0; $i<=$#field; ++$i) {
	$l->[$i] = $d->Label(-text=>$field[$i]);
	$e->[$i] = $d->Entry(-width=>4);
	$l->[$i]->grid($e->[$i]);
    }
    $d->Button(-text=>"OK", -command=>sub {
	$ans = [ map { $_->get(); } @$e ];
	$d->destroy();
    } )->grid(-columnspan=>2);
    $d->grab();
    $main->idletasks();
    $d->waitWindow();
    return @$ans;
}

$main = MainWindow->new();
$main->Button(-text=>"parameters", -command=>sub {
    my (@ans) = form( "Set Parameters of an Algorithm",
	"source:", "level:"
    );
    print "The user has entered: @ans\n";
} )->pack(-side=>"top");
$main->Button(-text=>"quit", -command=>sub { exit; })->pack(-side=>"top");

MainLoop();

