liverpole's technique is well worth knowing about, but is not the only way of achieving what you want with Tk's bind. Note the array ref passed in place of the subroutine ref in the bind here:

use strict; use warnings; use Tk; sub subbie_1 { my ($widget, $txt, $entry_var) = @_; $txt->insert('end', "$$entry_var\n"); } # Main Window my $mw = new MainWindow; my $entry_var = 'Some text'; #GUI Building Area my $frm_name = $mw -> Frame()->pack(); my $lab = $frm_name -> Label(-text=>"Name:")->pack(-side=>'left'); my $ent = $frm_name -> Entry(-textvariable=>\$entry_var)->pack(); #Text Area my $textarea = $mw -> Frame()->pack(); my $txt = $textarea -> Text(-width=>40, -height=>10)->pack(); $ent->bind('<Return>' => [\&subbie_1, $txt, \$entry_var]); MainLoop();

Update: note that because subbie_1 gets the widget ($ent in this case) there is no need to pass $entry_var so the following modified lines can be used:

... sub subbie_1 { my ($widget, $txt) = @_; $txt->insert('end', $widget->get () . "\n"); } ... $ent->bind('<Return>' => [\&subbie_1, $txt]); MainLoop();

In fact you may not need $entry_var at all now.


DWIM is Perl's answer to Gödel

In reply to Re: Newbie TK question by GrandFather
in thread Newbie TK question by hebes_99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.