#!/usr/bin/perl -w
# Demonstrate a simple pop-up window ("dialogue box") in Perl

use Tk;
use Tk::DialogBox;

# A Perl/Tk program must have a "main window", but we will hide it;  we also 
# don't need a MainLoop, because we will show the DialogBox when we want to.
$main = MainWindow->new();
$main->withdraw;

# Create the dialogue box.  Note the funny syntax - don't ask, just believe it ...
$dialog = $main->DialogBox( -title   => "Hello",
                            -buttons => [ "OK" ],
                          );
$dialog->add("Label", -text => "Please enter a value")->pack();
# The variable $data is used to receive the value typed into the dialogue box.
# It is also the default value displayed in the box before the user types anything.
$dialog->add("Entry", -textvariable => \$data,
                    # -show    => "*",  # use this line for passwords, otherwise omit
                      -width => 35)->pack();
# Now the dialogue box is ready for use.  

$data= "One";
$button= $dialog->Show();
print "Received $data\n";

# It can be used repeatedly without having to be created again,
# or you can create it again with different details.  

$data= "Two";
$button= $dialog->Show();
print "Received $data\n";

