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

Re: Why does widget->destroy give the error Tk::Error widget was deleted before its visibility changed?

by Anonymous Monk
on Apr 17, 2015 at 09:54 UTC ( [id://1123736]=note: print w/replies, xml ) Need Help??


in reply to Why does widget->destroy give the error Tk::Error widget was deleted before its visibility changed?

Where did you get this sample?

Tk::Error: window ".toplevel.frame1.hlist.menu" was deleted before its visibility changed ... You don't recieve the error if you only push the Exit button.

That is because no Menu object is created, and then destroyed before it could be displayed.

sub knock_on_door always creates a new menu in $popup_menu, and that variable always goes out of scope and is supposed to be destroyed, but Tk does you a favor and keeps it around because its knows you're not Coping with Scoping

Make sense?

If you make it a global and the only one, then you won't get that message

#~ my $pop_menu = $frame->Menu( -menuitems => our $pop_menu ; $pop_menu ||= $frame->Menu( -menuitems =>

But that isn't good practice, see tips at Re^3: Perl Tk Multiple Notebook Editing and Save (life cycle of variables) and the links it links

  • Comment on Re: Why does widget->destroy give the error Tk::Error widget was deleted before its visibility changed?
  • Download Code

Replies are listed 'Best First'.
Re^2: Why does widget->destroy give the error Tk::Error widget was deleted before its visibility changed?
by thomas.bystrom (Novice) on Apr 17, 2015 at 12:22 UTC
    Thanks!

    Your response pushed me forward.
    I did'nt solve the problem with making the pop_menu global.
    My solution is to withdraw the widget, because I want to reuse it later in my script (10 000 rows in 8 pm files).

    Thanks again for your Quick response.

      I am facing the same problem in several places in my application where I am using a menu bound to an hlist.

      I do not understand the proposed solution and how scoping plays a part

      In my application I am assigning the menu object to a hash element so that I can refer to it and try to destroy it when the window is going to close. like this:

      $winInfoRef->{MENU}= $winInfoRef->{HLIST}->Menu(-tearoff=>1,

      I have recreated the problem with the originally posted example code, I changed the lines to make $pop_menu a global as suggested (and relisted below)

      #~ my $pop_menu = $frame->Menu( -menuitems => our $pop_menu ; $pop_menu ||= $frame->Menu( -menuitems =>

      but I still get the same error:

      Tk::Error: window ".toplevel.frame.hlist.menu" was deleted before its +visibility changed at C:/Perl/site/lib/Tk/Widget.pm line 1000. Tk callback for tkwait <Button-1> (command bound to event)

      Thomas said he withdrew his menu, but I tried that too with no success(maybe I don't know how) Can anyone share more insight into this error?

        to Tk-804.033, then you don't have to learn anything

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-16 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found