previous has asked for the wisdom of the Perl Monks concerning the following question:

I've got a situation where...if I close a window by clicking the top right "X" button with with the mouse Tkx::tkwait works as expected and lets the program go past it. However if I use a key handler to trap Escape and issue the line Tkx::destroy($self->{win}); or $self->{win}->g_destroy; I seem to be in an endless loop...ending Dooneevent which I think is in the event loop but nothing passes tkwait. What's worse is the little test program I wrote to isolate the problem works well with either close method mouse or destroy statement so...it's useless in shedding light on the problem. BTW both of the destroy lines DO close the window so I'm not sure why tkwait doesn't see this and let the program flow by i.e. I printed the name of the window out just before tkwait so tkwait does "see" the window. At this stage any suggestions would be welcome. If necessary I'll try to build a more structurally representative model of my problem i.e. complete with skeleton object containing the window and use hierarchy. I suppose what's throwing me is why g_destroy works in some cases and not others re causing tkwait to let the program pass by.

Replies are listed 'Best First'.
Re: Tkx::__tkwait nightmare
by Anonymous Monk on Mar 07, 2016 at 01:38 UTC

    ...

    you need to post code that demonstrates the problem :)

    Its probably a typical scoping issue ...

      Will do. Thanks.
        Unfortunately all simplified models worked fine so...not representative. However, I solved my problem using the debugger + a shotgun approach on the real program. I noticed that when I closed the window via the window's std top right X button using the mouse... tkwait saw it fine. I wondered how that was different to my Escape key handler which simply invoked $win->g_destroy. I tried to see what happened from cicking the mouse in the top right X but couldn't easily stop the debugger just before that. I did however note that when I used a keyhandler...I seemed stuck in the event loop. All I did to solve the problem was insert a couple of returns in the call handler i.e. to prevent the code from hitting next which in Tcl terms seems equivalent to break which prevents further processing in the event loop. I'd have thought next was exactly what I needed but it seemed to keep me in the event loop...not let my own code continue. Irrespective it works now and I got some much neeeded debuggger experience. I like that you can script it's operation like gbd...Fantastic.