Basically , you're not using the right method "get", and variable scoping (what choroba said, closures don't work for globals). Compare your program to this (the commented lines are equivalent in effect)

I avoid closures by using references

#!/usr/bin/perl -- use strict; use warnings; use Tk; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { GoTk(); GoTk(); } sub GoTk { my $mw = tkinit( -title => "Frame delete test" ); my @mycolors = qw(red green blue violet yellow black); my @username_refs; for my $ix ( 0 .. 5 ) { my $username = ""; my $frame = $mw->Frame( -borderwidth => 10, -relief => 'groove', -background => $mycolors[$ix], )->pack; my $lbl = $frame->Label( -text => "Enter username: " )->pack; my $ent = $frame->Entry( -textvariable => \$username )->pack; my $btn = $frame->Button( -text => "Delete frame # " . $ix, #~ -command => [ $frame, 'destroy' ] -command => \&delete_parent_frame )->pack; push @username_refs, \$username; } my $exit = $mw -> Button( -text => "Exit", -command => [ $mw, 'destroy' ], )-> pack; $mw->$_ for qw/ withdraw deiconify raise focusForce update /; MainLoop; #~ print map { "You entered $$_\n" } @username_refs; dd\@username_refs; } ## end sub GoTk sub delete_parent_frame { my $button = $Tk::event->W; my $frame = $button->parent; #~ my $text = ( $frame->children )[1]; #~ my $text = ( grep { $_->isa('Tk::Entry') } $frame->children +)[0]; my( $text ) = grep { $_->isa( 'Tk::Entry' ) } $frame->children; #~ my $textvar = $text->cget( '-text' ); ## WEIRD! my $textvar = $text->cget( '-textvariable' ); print "You entered $textvar : $$textvar\n"; my $textstr = $text->get; print "You did entered $textstr\n"; $frame->destroy; return; } ## end sub delete_parent_frame

Read the tutorials in links in readmore in Re: Entry Edit Refresh (nested subs and closures)

Also, Hi, perlmonks has threaded discussions :) so click the reply link of the node you wish to reply to -- otherwise you're talking to yourself :) which coincidentally is a pretty good debugging technique :) 1 / 2


In reply to Re^5: Multiple frames by Anonymous Monk
in thread Multiple frames by delmejo

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.