|P is for Practical|
Re^5: Clearing anonymous Tk widgetsby murrayn (Novice)
|on Sep 03, 2012 at 06:54 UTC||Need Help??|
So this is my rewrite of the above using a hash to track each entry which I may want to delete...
This produces a Tk frame for each variable and puts three objects in that frame: 1) the variable name, as a Tk Label, which is the key to the %runtime hash, 2) the value from the %runtime hash as a Tk Entry field and 3) a Tk Button with text saying "Delete "Variable" Entry".
After that frame is built, it's inserted in $workframe on the next available line.
This all works nicely and the buttons all have their correct variable names written on them.
However, when I press the button, ANY button, the value of $widgetname is the last key accessed from the %runtime hash and that's the entry which is deleted from the hash and the subframe which is deleted from the workframe. A subsequent attempt to use any button generates an Tk error stating that I cannot delete an undefined object.
(I put the "my $deltgt=$widgetname" line in hoping that I might sufficiently localise the variable at "build" time that I could retain it ready for execution time - didn't work, not surprised.)
Perhaps I need a mechanism to read the text from the button which invoked the subroutine. The button is generated and remains static as the loop rolls on so the target variable name can be stored therein if only I could extract that.