9.15. How do I get the entry in an Entry?

You want to call get on the return value of the widget itself. Here is how it may be used in a simplified version of example 1.1 from the Tk::UserGuide where a Button is set up to call a sub where the call to get lies:

    #!/usr/bin/perl -w
    use strict;
    use Tk;

    my $main = MainWindow -> new();
    my $entry = $main -> Entry();
    $entry -> pack;
    $main->Button(-text => 'Print', 
                  -command => sub{do_print($entry)}
                  )->pack;
    MainLoop;

    sub do_print {
        my ($widget) = @_;
        my $entered = $widget -> get();
        print "The string \"$entered\" was entered.\n";
    }

Previous | Return to table of contents | Next