Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^6: Clearing anonymous Tk widgets

by murrayn (Acolyte)
on Sep 03, 2012 at 07:26 UTC ( #991375=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Clearing anonymous Tk widgets
in thread Clearing anonymous Tk widgets

Solved! The key is in the -command and passing parameters to a callback on a widget. The code above doesn't work because "$widgetname" is being evaluated at the time the button is released by which time the value has changed from what was intended. The challenge is to tell the callback associated with the button what the value was at the time the button was created and that is done by passing it as an argument to the callback thus:

-command=> [sub { my $deltgt = shift; print "Deleting \"$deltgt->$runtime{$deltgt}\"\n"; delete $runtime{$deltgt}; print "Hash entry deleted\n"; delete($wrLabel{$deltgt})->destroy(); print "Widget label deleted and destroyed\n"; delete($wrEntry{$deltgt})->destroy(); print "Widget entry deleted and destroyed\n"; delete($wrButton{$deltgt})->destroy(); print "Widget button deleted and destroyed\n"; $widgetrow{$deltgt} -> destroy(); print "Widget row destroyed\n"; }, $widgetname]


Comment on Re^6: Clearing anonymous Tk widgets
Download Code
Re^7: Clearing anonymous Tk widgets
by Anonymous Monk on Sep 03, 2012 at 16:39 UTC

    at the time the button was created and that is done by passing it as an argument to the callback thus:

    Or using a proper closure like I showed twice already

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-01 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls