Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Tk Menu Cascade has no delete method?

by mpersico (Scribe)
on Oct 17, 2012 at 13:41 UTC ( #999545=perlquestion: print w/replies, xml ) Need Help??
mpersico has asked for the wisdom of the Perl Monks concerning the following question:

I have built a gui containing a Tk::Notebook and a cascade menu. The menu has one entry for each tab that executes a raise command. No problem so far. I also have a separate menu item to close a tab. When I close the tab, I want to delete the corresponding menu entry. Problem is, when I go to delete the menu entry, I get: Tk::Error: Can't locate object method "delete" via package "Tk::Menu::Cascade" I thought Tk::Menu::Cascade inherited delete() from Tk::Menu. Am I setting up something incorrectly? Here is the snippet that builds the gui:
my $mw = new MainWindow( -title => "@{$G{reexec}}"); $mw->configure(-menu => my $menubar = $mw->Menu); my $nb = $mw->NoteBook(-width => $maxwidth)-> pack(-expand=>1, -fill => 'both'); my $filemenuitem = $menubar->cascade(-label=>'~File'); my $reexecmenuitem = $menubar->command(-label=>'~Re-exec', -command => \&reexec); my $closetabmenuitem = $menubar->command(-label => '~Close Tab', -command => sub { my $raised_page_name = $nb->raised(); my $raised_page_menu_index = $pages{$raised_page +_name}; $nb->delete($raised_page_name); ## No inherited delete here:? $filemenuitem->delete($raised_page_menu_index); });

Replies are listed 'Best First'.
Re: Tk Menu Cascade has no delete method?
by zentara (Archbishop) on Oct 17, 2012 at 17:33 UTC
    Hi, I'm not very good at the deeply nested menus, but here is a working example. P.S. Also see Deleting Menu Item from Menu
    #!/usr/bin/perl use warnings; use Tk; use strict; my $mw = new MainWindow; #Making a text area my $txt = $mw -> Scrolled('Text',-width => 30,-scrollbars=>'e') -> pac +k (); #Declare that there is a menu my $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); my $others = $mbar -> cascade(-label =>"Main", -underline=>0, -tearoff + => 0); my $help = $mbar -> cascade(-label =>"Help", -underline=>0, -tearoff = +> 0); ## Others Menu ## my $insert = $others -> cascade(-label =>"Insert", -underline => 0, -t +earoff => 0); my $Btn1 = $insert -> command(-label =>"Name",-command=>sub{print "2\n +";}); my $Btn2 = $insert -> command(-label =>"Website"); my $Btn3 = $insert -> command(-label =>"Email"); $others-> command(-label => "Delete", -underline=>0, -command=>sub {delete_menu();} ); $help-> command(-label => "Add", -underline=>0, -command=>sub {add_menu();} ); MainLoop; sub add_menu{ # must be cascade, checkbutton, command, radiobutton, or separator $Btn1->parentMenu->add('command',-label => time, -command=>sub{print "3\n";}); } sub delete_menu { print "1\n"; #$Btn1->parentMenu->delete(0); #or $Btn1->parentMenu->delete($Btn1->parentMenu->index($Btn1->[1])); + #or $Btn1->[0]->delete($Btn1->[0]->index($Btn1->[1])); #or $$Btn1[0]->delete($$Btn1[0]->index($$Btn1[1])); # or $insert->menu->delete($insert->menu->index($$Btn1[1])); + }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999545]
Approved by nemesdani
Front-paged by Tanktalus
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2018-02-20 14:22 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (271 votes). Check out past polls.