|No such thing as a small change|
How to destroy and re-create bound widgetsby Phinix (Acolyte)
|on Nov 03, 2012 at 06:10 UTC||Need Help??|
Phinix has asked for the
wisdom of the Perl Monks concerning the following question:
I am having difficulty attempting to destroy widgets I have bound to mouse click events. All the documentation I read seems to indicate the problem is likely related to internal tables maintained for destroyed widgets, however none seem to elaborate on how to clear them, or how to "detach" or "unbind" events from widgets so they may be safely destroyed and re-created from scratch.
The program I am writing reaches a point where it needs to delete all dynamically created "buttons" (widgets with mouse binds on them) and then re-create the first of them by invoking a sub-routine to basically start over. Below is a sample of the code, to show the basic concept
Basically what it does is set up the container structure, then invoke &scan1start; which is a subroutine to build the first fake widget button, and bind it to right and left mouse (not the reset button, leave that alone for now!) I am using canvas as the bind widget because I want to give it a background image without inheriting the functionality of a regular button.
Clicking this first fake widget button button runs the next two subroutines to create two more buttons (and also changes the first button's color). Clicking either of these new buttons will change their color, and right-clicking will change it back. Right-clicking the first button hides the two higher buttons, but only if they are "off" (black in this example.)You can test all of this and it works fine, until you click the reset button. This button is supposed to destroy all the buttons, then run the initial subroutine to re-create the first button and set up it's initial bindings again, basically starting all over. However, as you can see perl complains about a bound event and the button is never re-created.
Sorry if this seems similar to another question I asked recently about canvas items, however that example was somewhat unclear and presented in a misleading context.
This is specifically an issue with unbinding/destroying bound widgets. I have attempted it with numerous other widget types (buttons, images), inside numerous container types and had the same result with all of them.
I know I am not the most well-versed in the language but this particular snag is really starting to recede my hairline!
EDIT: Just thought I would add, this same "command bound to event" error crops up when I attempt to use ->delete('all') and formForget instead of destroy. Very very frustrating.