<HTML>
<HEAD><TITLE> 9.15. How do I get the entry in an Entry?</TITLE></HEAD>
<BODY><a name="A9.15"> 9.15. How do I <kbd>get</kbd> the entry in an <kbd>Entry</kbd>?</a>
<hr>
</p><p>
You want to call <kbd>get</kbd> 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
<a href="pod/UserGuide.html">Tk::UserGuide</a> where a <kbd>Button</kbd> is set
up to call a <kbd>sub</kbd> where the call to <kbd>get</kbd> lies:
<pre>
#!/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";
}
</pre>
<hr>
<p><a href="qna9.14.html">Previous</a> | Return to <a href="ptkTOC.html#TOC9.15">table of contents</a> | <a href="qna9.16.html">Next</a>
</p><hr><p>
</BODY></HTML>