Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Multiple frames

by Anonymous Monk
on Aug 31, 2013 at 14:46 UTC ( [id://1051737]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Multiple frames
in thread Multiple frames

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

Replies are listed 'Best First'.
Re^6: Multiple frames
by delmejo (Initiate) on Sep 06, 2013 at 01:57 UTC
    Thank you for the suggestions. I am reading through the link you posted and some others and am getting closer. Once I have more I'll post the code. Hopefully this time I clicked the right reply :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1051737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-29 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found